@Test public void testReadSampleTypeList_DocumentArray() throws Exception { JsonXMLArrayProvider provider = new JsonXMLArrayProvider(null); Annotation[] annotations = new Annotation[]{JsonXMLDefault.class.getAnnotation(JsonXML.class)}; Type type = getClass().getDeclaredField("sampleTypeList").getGenericType(); String json = "[{\"sampleType\":{\"element\":\"hello\"}},{\"sampleType\":{\"element\":\"world\"}}]"; @SuppressWarnings("unchecked") List<SampleType> list = (List<SampleType>)provider.read(List.class, type, annotations, MediaType.APPLICATION_JSON_TYPE, null, new StringReader(json)); Assert.assertEquals(2, list.size()); Assert.assertEquals("hello", list.get(0).element); Assert.assertEquals("world", list.get(1).element); }
@Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); List<?> list; try { list = readArray(componentType, config, getContext(componentType, mediaType), stream); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } if (list == null) { return null; } else if (type.isArray()) { return toArray(list, componentType); } else { Collection<Object> collection = createCollection(type); if (collection == null) { throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } collection.addAll(list); return collection; } }
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); List<?> list; try { list = readArray(componentType, config, getContext(componentType, mediaType), stream); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } if (list == null) { return null; } else if (type.isArray()) { return toArray(list, componentType); } else { Collection<Object> collection = createCollection(type); if (collection == null) { throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } collection.addAll(list); return collection; } } }
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); List<?> list; try { list = readArray(componentType, config, getContext(componentType, mediaType), stream); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } if (list == null) { return null; } else if (type.isArray()) { return toArray(list, componentType); } else { Collection<Object> collection = createCollection(type); if (collection == null) { throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } collection.addAll(list); return collection; } } JsonXMLArrayProvider(@Context Providers providers); }
JsonXMLArrayProvider extends AbstractJsonXMLProvider { @Override public Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); List<?> list; try { list = readArray(componentType, config, getContext(componentType, mediaType), stream); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } if (list == null) { return null; } else if (type.isArray()) { return toArray(list, componentType); } else { Collection<Object> collection = createCollection(type); if (collection == null) { throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } collection.addAll(list); return collection; } } 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 Object read( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, Reader stream) throws IOException, WebApplicationException { Class<?> componentType = getComponentType(type, genericType); JsonXML config = getJsonXML(componentType, annotations); List<?> list; try { list = readArray(componentType, config, getContext(componentType, mediaType), stream); } catch (XMLStreamException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } catch (JAXBException e) { throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR); } if (list == null) { return null; } else if (type.isArray()) { return toArray(list, componentType); } else { Collection<Object> collection = createCollection(type); if (collection == null) { throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR); } collection.addAll(list); return collection; } } 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);  }