use of com.zimbra.soap.jaxb.TransientTester in project zm-mailbox by Zimbra.
the class JaxbToJsonTest method transientHandling.
/**
* XmlTransient handling - Need to ignore fields with {@link XmlElementRef} annotation.
*/
@Test
public void transientHandling() throws Exception {
String str = "my string - should NOT be serialized";
int num = 321;
TransientTester jaxb = new TransientTester(str, num);
Element jsonJaxbElem = JacksonUtil.jaxbToJSONElement(jaxb);
Element xmlElem = JaxbUtil.jaxbToElement(jaxb, Element.XMLElement.mFactory, true, false);
logDebug("JSONElement from JAXB ---> prettyPrint\n%1$s", jsonJaxbElem.prettyPrint());
logDebug("XmlElement (for comparison) ---> prettyPrint\n%1$s", xmlElem.prettyPrint());
TransientTester roundtrippedX = JaxbUtil.elementToJaxb(xmlElem, TransientTester.class);
TransientTester roundtripped = JaxbUtil.elementToJaxb(jsonJaxbElem, TransientTester.class);
Assert.assertEquals("roundtrippedX num", new Integer(num), roundtrippedX.getNummer());
Assert.assertNull("roundtrippedX str", roundtrippedX.getToBeIgnored());
Assert.assertEquals("roundtripped num", new Integer(num), roundtripped.getNummer());
Assert.assertNull("roundtripped str", roundtripped.getToBeIgnored());
}
Aggregations