@Test public void testReadObjectSampleRootElement() throws Exception { JsonXML config = JsonXMLDefault.class.getAnnotation(JsonXML.class); String json = "{\"sampleRootElement\":{\"@attribute\":\"hello\",\"elements\":[\"world\"]}}"; JAXBContext context = JAXBContext.newInstance(SampleRootElement.class); SampleRootElement sampleRootElement = new JsonXMLBinder().readObject(SampleRootElement.class, config, context, new StringReader(json)); Assert.assertEquals("hello", sampleRootElement.attribute); Assert.assertEquals("world", sampleRootElement.elements.get(0)); }
public <T> T readObject(Class<? extends T> type, JsonXML config, JAXBContext context, Reader stream) throws XMLStreamException, JAXBException { checkBindable(type); XMLStreamReader reader = createXMLStreamReader(type, config, stream); T result; if (reader.isCharacters() && reader.getText() == null) { result = null; } else { reader.require(XMLStreamConstants.START_DOCUMENT, null, null); Unmarshaller unmarshaller = context.createUnmarshaller(); result = unmarshal(type, config, unmarshaller, reader); reader.require(XMLStreamConstants.END_DOCUMENT, null, null); } reader.close(); return result; }
JsonXMLBinder { public <T> T readObject(Class<? extends T> type, JsonXML config, JAXBContext context, Reader stream) throws XMLStreamException, JAXBException { checkBindable(type); XMLStreamReader reader = createXMLStreamReader(type, config, stream); T result; if (reader.isCharacters() && reader.getText() == null) { result = null; } else { reader.require(XMLStreamConstants.START_DOCUMENT, null, null); Unmarshaller unmarshaller = context.createUnmarshaller(); result = unmarshal(type, config, unmarshaller, reader); reader.require(XMLStreamConstants.END_DOCUMENT, null, null); } reader.close(); return result; } }
JsonXMLBinder { public <T> T readObject(Class<? extends T> type, JsonXML config, JAXBContext context, Reader stream) throws XMLStreamException, JAXBException { checkBindable(type); XMLStreamReader reader = createXMLStreamReader(type, config, stream); T result; if (reader.isCharacters() && reader.getText() == null) { result = null; } else { reader.require(XMLStreamConstants.START_DOCUMENT, null, null); Unmarshaller unmarshaller = context.createUnmarshaller(); result = unmarshal(type, config, unmarshaller, reader); reader.require(XMLStreamConstants.END_DOCUMENT, null, null); } reader.close(); return result; } JsonXMLBinder(); protected  JsonXMLBinder(boolean writeDocumentArray); protected  JsonXMLBinder(JsonXMLRootProvider rootProvider, boolean writeDocumentArray); }
JsonXMLBinder { public <T> T readObject(Class<? extends T> type, JsonXML config, JAXBContext context, Reader stream) throws XMLStreamException, JAXBException { checkBindable(type); XMLStreamReader reader = createXMLStreamReader(type, config, stream); T result; if (reader.isCharacters() && reader.getText() == null) { result = null; } else { reader.require(XMLStreamConstants.START_DOCUMENT, null, null); Unmarshaller unmarshaller = context.createUnmarshaller(); result = unmarshal(type, config, unmarshaller, reader); reader.require(XMLStreamConstants.END_DOCUMENT, null, null); } 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> T readObject(Class<? extends T> type, JsonXML config, JAXBContext context, Reader stream) throws XMLStreamException, JAXBException { checkBindable(type); XMLStreamReader reader = createXMLStreamReader(type, config, stream); T result; if (reader.isCharacters() && reader.getText() == null) { result = null; } else { reader.require(XMLStreamConstants.START_DOCUMENT, null, null); Unmarshaller unmarshaller = context.createUnmarshaller(); result = unmarshal(type, config, unmarshaller, reader); reader.require(XMLStreamConstants.END_DOCUMENT, null, null); } 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);  }