XmlFormatter extends Formatter<String> { @Override public void setup(OperatorContext context) { JAXBContext ctx; try { ctx = JAXBContext.newInstance(getClazz()); marshaller = ctx.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, prettyPrint); } catch (JAXBException e) { DTThrowable.wrapIfChecked(e); } } XmlFormatter(); @Override void setup(OperatorContext context); @Override String convert(Object tuple); String getAlias(); void setAlias(String alias); String getDateFormat(); void setDateFormat(String dateFormat); boolean isPrettyPrint(); void setPrettyPrint(boolean prettyPrint);  }
@Test public void testPojoToXmlWithoutAlias() { EmployeeBean e = new EmployeeBean(); e.setName("john"); e.setEid(1); e.setDept("cs"); e.setDateOfJoining(new DateTime().withYear(2015).withMonthOfYear(1).withDayOfYear(1).toDate()); operator.setup(null); operator.in.process(e); Assert.assertEquals(1, validDataSink.collectedTuples.size()); Assert.assertEquals(0, invalidDataSink.collectedTuples.size()); String expected = "<EmployeeBean>" + "<name>john</name>" + "<dept>cs</dept>" + "<eid>1</eid>" + "<dateOfJoining>2015-01-01</dateOfJoining>" + "</EmployeeBean>"; Assert.assertEquals(expected, validDataSink.collectedTuples.get(0)); }
@Test public void testPojoToXmlWithoutAliasHeirarchical() { EmployeeBean e = new EmployeeBean(); e.setName("john"); e.setEid(1); e.setDept("cs"); e.setDateOfJoining(new DateTime().withYear(2015).withMonthOfYear(1).withDayOfYear(1).toDate()); Address address = new Address(); address.setCity("new york"); address.setCountry("US"); e.setAddress(address); operator.setup(null); operator.in.process(e); LOG.debug("{}", validDataSink.collectedTuples.get(0)); Assert.assertEquals(1, validDataSink.collectedTuples.size()); Assert.assertEquals(0, invalidDataSink.collectedTuples.size()); String expected = "<EmployeeBean>" + "<name>john</name>" + "<dept>cs</dept>" + "<eid>1</eid>" + "<dateOfJoining>2015-01-01</dateOfJoining>" + "<address>" + "<city>new york</city>" + "<country>US</country>" + "</address>" + "</EmployeeBean>"; Assert.assertEquals(expected, validDataSink.collectedTuples.get(0)); }