Search in sources :

Example 1 with TransientTester

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());
}
Also used : TransientTester(com.zimbra.soap.jaxb.TransientTester) XmlAnyElement(javax.xml.bind.annotation.XmlAnyElement) Element(com.zimbra.common.soap.Element) XMLElement(com.zimbra.common.soap.Element.XMLElement) JSONElement(com.zimbra.common.soap.Element.JSONElement) XmlElement(javax.xml.bind.annotation.XmlElement) FilterTest(com.zimbra.soap.mail.type.FilterTest) Test(org.junit.Test)

Aggregations

Element (com.zimbra.common.soap.Element)1 JSONElement (com.zimbra.common.soap.Element.JSONElement)1 XMLElement (com.zimbra.common.soap.Element.XMLElement)1 TransientTester (com.zimbra.soap.jaxb.TransientTester)1 FilterTest (com.zimbra.soap.mail.type.FilterTest)1 XmlAnyElement (javax.xml.bind.annotation.XmlAnyElement)1 XmlElement (javax.xml.bind.annotation.XmlElement)1 Test (org.junit.Test)1