Search in sources :

Example 1 with WrappedKeyValuePairsTester

use of com.zimbra.soap.jaxb.WrappedKeyValuePairsTester in project zm-mailbox by Zimbra.

the class JaxbToJsonTest method wrappedZimbraKeyValuePairsAnnotation.

/**
     * Desired JSON :
     * {
     *   "wrapper": {
     *     "_attrs": {
     *       "key1": "value1",
     *       "key2": "value2"
     *     }
     *   },
     *   "_jsns": "urn:zimbraTest"
     * }
     */
@Test
public void wrappedZimbraKeyValuePairsAnnotation() throws Exception {
    Element jsonElem = JSONElement.mFactory.createElement(QName.get("key-value-pairs", "urn:zimbraTest"));
    Element wrapperElem = jsonElem.addUniqueElement("wrapper");
    wrapperElem.addKeyValuePair("key1", "value1");
    wrapperElem.addKeyValuePair("key2", "value2");
    List<KeyValuePair> attrs = Lists.newArrayList();
    attrs.add(new KeyValuePair("key1", "value1"));
    attrs.add(new KeyValuePair("key2", "value2"));
    WrappedKeyValuePairsTester jaxb = new WrappedKeyValuePairsTester(attrs);
    Element jsonJaxbElem = JacksonUtil.jaxbToJSONElement(jaxb);
    logDebug("JSONElement (for comparison) ---> prettyPrint\n%1$s", jsonElem.prettyPrint());
    logDebug("JSONElement from JAXB ---> prettyPrint\n%1$s", jsonJaxbElem.prettyPrint());
    Assert.assertEquals("prettyPrint", jsonElem.prettyPrint(), jsonJaxbElem.prettyPrint());
    WrappedKeyValuePairsTester roundtripped = JaxbUtil.elementToJaxb(jsonJaxbElem, WrappedKeyValuePairsTester.class);
    List<com.zimbra.common.soap.Element.KeyValuePair> elemKVPs = jsonJaxbElem.getElement("wrapper").listKeyValuePairs();
    Assert.assertEquals("elemKVP num", 2, elemKVPs.size());
    List<KeyValuePair> kvps = roundtripped.getAttrList();
    Assert.assertEquals("roundtripped kvps num", 2, kvps.size());
}
Also used : KeyValuePair(com.zimbra.soap.type.KeyValuePair) 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) WrappedKeyValuePairsTester(com.zimbra.soap.jaxb.WrappedKeyValuePairsTester) 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 WrappedKeyValuePairsTester (com.zimbra.soap.jaxb.WrappedKeyValuePairsTester)1 FilterTest (com.zimbra.soap.mail.type.FilterTest)1 KeyValuePair (com.zimbra.soap.type.KeyValuePair)1 XmlAnyElement (javax.xml.bind.annotation.XmlAnyElement)1 XmlElement (javax.xml.bind.annotation.XmlElement)1 Test (org.junit.Test)1