@Test public void testWriteObjectSampleType() throws Exception { JsonXML config = JsonXMLDefault.class.getAnnotation(JsonXML.class); SampleType sampleType = new SampleType(); sampleType.element = "hi!"; StringWriter writer = new StringWriter(); JAXBContext context = JAXBContext.newInstance(SampleType.class); new JsonXMLBinder().writeObject(SampleType.class, config, context, writer, sampleType); String json = "{\"sampleType\":{\"element\":\"hi!\"}}"; Assert.assertEquals(json, writer.toString()); }
@Test public void testMarshallSampleType() throws Exception { JsonXML config = JsonXMLDefault.class.getAnnotation(JsonXML.class); StringWriter result = new StringWriter(); Class<?> type = SampleType.class; SampleType sampleType = new SampleType(); sampleType.element = "hi!"; XMLStreamWriter writer = new JsonXMLBinder().createXMLStreamWriter(type, config, result); Marshaller marshaller = JAXBContext.newInstance(type).createMarshaller(); new JsonXMLBinder().marshal(type, config, marshaller, writer, sampleType); writer.close(); String json = "{\"sampleType\":{\"element\":\"hi!\"}}"; Assert.assertEquals(json, result.toString()); }