@Test public void testReadArraySampleRootElement_DocumentArray() throws Exception { JsonXML config = JsonXMLDefault.class.getAnnotation(JsonXML.class); String json = "[{\"sampleRootElement\":{\"@attribute\":\"hello\"}},{\"sampleRootElement\":{\"@attribute\":\"world\"}}]"; JAXBContext context = JAXBContext.newInstance(SampleRootElement.class); List<SampleRootElement> list = new JsonXMLBinder().readArray(SampleRootElement.class, config, context, new StringReader(json)); Assert.assertEquals(2, list.size()); Assert.assertEquals("hello", list.get(0).attribute); Assert.assertEquals("world", list.get(1).attribute); }
public <T> List<T> readArray(Class<? extends T> type, JsonXML config, JAXBContext context, Reader stream) throws XMLStreamException, JAXBException { checkBindable(type); XMLStreamReader reader = createXMLStreamReader(type, config, stream); List<T> result; if (reader.isCharacters() && reader.getText() == null) { result = null; } else { boolean documentArray = JsonXMLStreamConstants.MULTIPLE_PI_TARGET.equals(reader.getPITarget()); Unmarshaller unmarshaller = context.createUnmarshaller(); while (reader.hasNext() && !reader.isStartElement() && !reader.isCharacters()) { reader.next(); } result = new ArrayList<T>(); while (reader.hasNext() || reader.isCharacters() && reader.getText() == null) { if (reader.isCharacters() && reader.getText() == null) { result.add(null); if (reader.hasNext()) { reader.next(); } else { break; } } else { result.add(unmarshal(type, config, unmarshaller, reader)); if (documentArray && reader.hasNext()) { reader.next(); } } } } reader.close(); return result; }
JsonXMLBinder { public <T> List<T> readArray(Class<? extends T> type, JsonXML config, JAXBContext context, Reader stream) throws XMLStreamException, JAXBException { checkBindable(type); XMLStreamReader reader = createXMLStreamReader(type, config, stream); List<T> result; if (reader.isCharacters() && reader.getText() == null) { result = null; } else { boolean documentArray = JsonXMLStreamConstants.MULTIPLE_PI_TARGET.equals(reader.getPITarget()); Unmarshaller unmarshaller = context.createUnmarshaller(); while (reader.hasNext() && !reader.isStartElement() && !reader.isCharacters()) { reader.next(); } result = new ArrayList<T>(); while (reader.hasNext() || reader.isCharacters() && reader.getText() == null) { if (reader.isCharacters() && reader.getText() == null) { result.add(null); if (reader.hasNext()) { reader.next(); } else { break; } } else { result.add(unmarshal(type, config, unmarshaller, reader)); if (documentArray && reader.hasNext()) { reader.next(); } } } } reader.close(); return result; } }
JsonXMLBinder { public <T> List<T> readArray(Class<? extends T> type, JsonXML config, JAXBContext context, Reader stream) throws XMLStreamException, JAXBException { checkBindable(type); XMLStreamReader reader = createXMLStreamReader(type, config, stream); List<T> result; if (reader.isCharacters() && reader.getText() == null) { result = null; } else { boolean documentArray = JsonXMLStreamConstants.MULTIPLE_PI_TARGET.equals(reader.getPITarget()); Unmarshaller unmarshaller = context.createUnmarshaller(); while (reader.hasNext() && !reader.isStartElement() && !reader.isCharacters()) { reader.next(); } result = new ArrayList<T>(); while (reader.hasNext() || reader.isCharacters() && reader.getText() == null) { if (reader.isCharacters() && reader.getText() == null) { result.add(null); if (reader.hasNext()) { reader.next(); } else { break; } } else { result.add(unmarshal(type, config, unmarshaller, reader)); if (documentArray && reader.hasNext()) { reader.next(); } } } } reader.close(); return result; } JsonXMLBinder(); protected  JsonXMLBinder(boolean writeDocumentArray); protected  JsonXMLBinder(JsonXMLRootProvider rootProvider, boolean writeDocumentArray); }
JsonXMLBinder { public <T> List<T> readArray(Class<? extends T> type, JsonXML config, JAXBContext context, Reader stream) throws XMLStreamException, JAXBException { checkBindable(type); XMLStreamReader reader = createXMLStreamReader(type, config, stream); List<T> result; if (reader.isCharacters() && reader.getText() == null) { result = null; } else { boolean documentArray = JsonXMLStreamConstants.MULTIPLE_PI_TARGET.equals(reader.getPITarget()); Unmarshaller unmarshaller = context.createUnmarshaller(); while (reader.hasNext() && !reader.isStartElement() && !reader.isCharacters()) { reader.next(); } result = new ArrayList<T>(); while (reader.hasNext() || reader.isCharacters() && reader.getText() == null) { if (reader.isCharacters() && reader.getText() == null) { result.add(null); if (reader.hasNext()) { reader.next(); } else { break; } } else { result.add(unmarshal(type, config, unmarshaller, reader)); if (documentArray && reader.hasNext()) { reader.next(); } } } } reader.close(); return result; } JsonXMLBinder(); protected  JsonXMLBinder(boolean writeDocumentArray); protected  JsonXMLBinder(JsonXMLRootProvider rootProvider, boolean writeDocumentArray); boolean isBindable(Class<?> type); T readObject(Class<? extends T> type, JsonXML config, JAXBContext context, Reader stream); void writeObject(Class<?> type, JsonXML config, JAXBContext context, Writer stream, Object value); List<T> readArray(Class<? extends T> type, JsonXML config, JAXBContext context, Reader stream); void writeArray(Class<?> type, JsonXML config, JAXBContext context, Writer stream, Collection<?> collection); }
JsonXMLBinder { public <T> List<T> readArray(Class<? extends T> type, JsonXML config, JAXBContext context, Reader stream) throws XMLStreamException, JAXBException { checkBindable(type); XMLStreamReader reader = createXMLStreamReader(type, config, stream); List<T> result; if (reader.isCharacters() && reader.getText() == null) { result = null; } else { boolean documentArray = JsonXMLStreamConstants.MULTIPLE_PI_TARGET.equals(reader.getPITarget()); Unmarshaller unmarshaller = context.createUnmarshaller(); while (reader.hasNext() && !reader.isStartElement() && !reader.isCharacters()) { reader.next(); } result = new ArrayList<T>(); while (reader.hasNext() || reader.isCharacters() && reader.getText() == null) { if (reader.isCharacters() && reader.getText() == null) { result.add(null); if (reader.hasNext()) { reader.next(); } else { break; } } else { result.add(unmarshal(type, config, unmarshaller, reader)); if (documentArray && reader.hasNext()) { reader.next(); } } } } reader.close(); return result; } JsonXMLBinder(); protected  JsonXMLBinder(boolean writeDocumentArray); protected  JsonXMLBinder(JsonXMLRootProvider rootProvider, boolean writeDocumentArray); boolean isBindable(Class<?> type); T readObject(Class<? extends T> type, JsonXML config, JAXBContext context, Reader stream); void writeObject(Class<?> type, JsonXML config, JAXBContext context, Writer stream, Object value); List<T> readArray(Class<? extends T> type, JsonXML config, JAXBContext context, Reader stream); void writeArray(Class<?> type, JsonXML config, JAXBContext context, Writer stream, Collection<?> collection);  }