JsonXMLMapper { public void writeObject(Writer writer, T value) throws JAXBException, XMLStreamException { binder.writeObject(type, config, context, writer, value); } JsonXMLMapper(Class<T> type);  JsonXMLMapper(Class<T> type, JsonXML config); T readObject(Reader reader); T readObject(InputStream input); void writeObject(Writer writer, T value); void writeObject(OutputStream output, T value); List<T> readArray(Reader reader); List<T> readArray(InputStream input); void writeArray(Writer writer, Collection<T> collection); void writeArray(OutputStream output, Collection<T> collection);  }
@Test public void testWriteXmlRootElement() throws Exception { JsonXMLMapper<SampleRootElement> mapper = new JsonXMLMapper<SampleRootElement>(SampleRootElement.class); StringWriter writer = new StringWriter(); SampleRootElement value = new SampleRootElement(); mapper.writeObject(writer, value); writer.close(); Assert.assertEquals("{\"sampleRootElement\":null}", writer.toString()); }
@Test public void testWriteXmlType() throws Exception { JsonXML config = JsonXMLDefault.class.getAnnotation(JsonXML.class); JsonXMLMapper<SampleType> mapper = new JsonXMLMapper<SampleType>(SampleType.class, config); StringWriter writer = new StringWriter(); SampleType value = new SampleType(); mapper.writeObject(writer, value); writer.close(); Assert.assertEquals("{\"sampleType\":null}", writer.toString()); }
@Test public void testWriteXmlTypeWithNamespace() throws Exception { JsonXML config = JsonXMLDefault.class.getAnnotation(JsonXML.class); JsonXMLMapper<SampleTypeWithNamespace> mapper = new JsonXMLMapper<SampleTypeWithNamespace>(SampleTypeWithNamespace.class, config); StringWriter writer = new StringWriter(); SampleTypeWithNamespace value = new SampleTypeWithNamespace(); mapper.writeObject(writer, value); writer.close(); Assert.assertEquals("{\"ns2:sampleTypeWithNamespace\":{\"@xmlns:ns2\":\"urn:staxon:jaxb:test\"}}", writer.toString()); }