@Test public void testWriteEmptyList() throws Exception { JsonXMLArrayProvider provider = new JsonXMLArrayProvider(null); Annotation[] annotations = new Annotation[0]; Type type = getClass().getDeclaredField("sampleRootElementList").getGenericType(); List<SampleRootElement> list = new ArrayList<SampleRootElement>(); StringWriter writer = new StringWriter(); provider.write(List.class, type, annotations, MediaType.APPLICATION_JSON_TYPE, null, writer, list); String json = "[]"; Assert.assertEquals(json, writer.toString()); }
@Override public void write( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, Writer stream, Object entry) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); Collection<?> collection; if (entry == null) { collection = null; } else if (type.isArray()) { collection = Arrays.asList((Object[]) entry); } else { collection = (Collection<?>) entry; } try { writeArray(componentType, config, getContext(componentType, mediaType), stream, collection); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } }
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public void write( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, Writer stream, Object entry) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); Collection<?> collection; if (entry == null) { collection = null; } else if (type.isArray()) { collection = Arrays.asList((Object[]) entry); } else { collection = (Collection<?>) entry; } try { writeArray(componentType, config, getContext(componentType, mediaType), stream, collection); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } } }
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public void write( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, Writer stream, Object entry) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); Collection<?> collection; if (entry == null) { collection = null; } else if (type.isArray()) { collection = Arrays.asList((Object[]) entry); } else { collection = (Collection<?>) entry; } try { writeArray(componentType, config, getContext(componentType, mediaType), stream, collection); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } } JsonXMLArrayProvider(@Context Providers providers); }
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public void write( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, Writer stream, Object entry) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); Collection<?> collection; if (entry == null) { collection = null; } else if (type.isArray()) { collection = Arrays.asList((Object[]) entry); } else { collection = (Collection<?>) entry; } try { writeArray(componentType, config, getContext(componentType, mediaType), stream, collection); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } } JsonXMLArrayProvider(@Context Providers providers); @Override Object read(
			Class<?> type,
			Type genericType,
			Annotation[] annotations,
			MediaType mediaType,
			MultivaluedMap<String, String> httpHeaders,
			Reader stream); @Override void write(
			Class<?> type,
			Type genericType,
			Annotation[] annotations,
			MediaType mediaType,
			MultivaluedMap<String, Object> httpHeaders,
			Writer stream,
			Object entry); }
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public void write( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, Writer stream, Object entry) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); Collection<?> collection; if (entry == null) { collection = null; } else if (type.isArray()) { collection = Arrays.asList((Object[]) entry); } else { collection = (Collection<?>) entry; } try { writeArray(componentType, config, getContext(componentType, mediaType), stream, collection); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } } JsonXMLArrayProvider(@Context Providers providers); @Override Object read(
			Class<?> type,
			Type genericType,
			Annotation[] annotations,
			MediaType mediaType,
			MultivaluedMap<String, String> httpHeaders,
			Reader stream); @Override void write(
			Class<?> type,
			Type genericType,
			Annotation[] annotations,
			MediaType mediaType,
			MultivaluedMap<String, Object> httpHeaders,
			Writer stream,
			Object entry);  }