Search in sources :

Example 1 with EnumElemList

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

the class JaxbToJsonTest method enumElemList.

/**
     *  Testing form:
     *      {@code @XmlElement(name="enum-entry", required=false)
     *      private List<ViewEnum> entries = Lists.newArrayList();}
     * Desired JSON :
     *      {
     *        "enum-entry": [
     *          {
     *            "_content": "appointment"
     *          },
     *          {
     *            "_content": ""
     *          },
     *          {
     *            "_content": "document"
     *          }],
     *        "_jsns": "urn:zimbraTest"
     */
@Test
public void enumElemList() throws Exception {
    Element jsonElem = JSONElement.mFactory.createElement(QName.get("enum-elem-list", "urn:zimbraTest"));
    jsonElem.addElement("enum-entry").addText(ViewEnum.APPOINTMENT.toString());
    jsonElem.addElement("enum-entry").addText(ViewEnum.UNKNOWN.toString());
    jsonElem.addElement("enum-entry").addText(ViewEnum.DOCUMENT.toString());
    logDebug("JSONElement (for comparison) ---> prettyPrint\n%1$s", jsonElem.prettyPrint());
    EnumElemList tstr = new EnumElemList();
    tstr.addEntry(ViewEnum.APPOINTMENT);
    tstr.addEntry(ViewEnum.UNKNOWN);
    tstr.addEntry(ViewEnum.DOCUMENT);
    Element jsonJaxbElem = JacksonUtil.jaxbToJSONElement(tstr);
    EnumElemList roundtripped = JaxbUtil.elementToJaxb(jsonJaxbElem, EnumElemList.class);
    logDebug("JSONElement from JAXB ---> prettyPrint\n%1$s", jsonJaxbElem.prettyPrint());
    List<Element> jsonElems = jsonJaxbElem.listElements();
    List<ViewEnum> entries = roundtripped.getEntries();
    Assert.assertEquals("jsonElems num", 3, jsonElems.size());
    Assert.assertEquals("entries num", 3, entries.size());
    Assert.assertTrue("has APPOINTMENT", entries.contains(ViewEnum.APPOINTMENT));
    Assert.assertTrue("has UNKNOWN", entries.contains(ViewEnum.UNKNOWN));
    Assert.assertTrue("has DOCUMENT", entries.contains(ViewEnum.DOCUMENT));
}
Also used : EnumElemList(com.zimbra.soap.jaxb.EnumElemList) WrappedEnumElemList(com.zimbra.soap.jaxb.WrappedEnumElemList) 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) ViewEnum(com.zimbra.soap.jaxb.ViewEnum) FilterTest(com.zimbra.soap.mail.type.FilterTest) Test(org.junit.Test)

Example 2 with EnumElemList

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

the class JaxbToJsonTest method emptyEnumElemList.

/**
     * Desired JSON :
     * {
     *   "_jsns": "urn:zimbraTest"
     * }
     */
@Test
public void emptyEnumElemList() throws Exception {
    EnumElemList tstr = new EnumElemList();
    Element jsonJaxbElem = JacksonUtil.jaxbToJSONElement(tstr);
    logDebug("JSONElement from JAXB FOR EMPTY LIST ---> prettyPrint\n%1$s", jsonJaxbElem.prettyPrint());
    EnumElemList roundtripped = JaxbUtil.elementToJaxb(jsonJaxbElem, EnumElemList.class);
    List<Element> jsonElems = jsonJaxbElem.listElements();
    List<ViewEnum> entries = roundtripped.getEntries();
    Assert.assertEquals("jsonElems num", 0, jsonElems.size());
    Assert.assertEquals("entries num", 0, entries.size());
}
Also used : EnumElemList(com.zimbra.soap.jaxb.EnumElemList) WrappedEnumElemList(com.zimbra.soap.jaxb.WrappedEnumElemList) 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) ViewEnum(com.zimbra.soap.jaxb.ViewEnum) FilterTest(com.zimbra.soap.mail.type.FilterTest) Test(org.junit.Test)

Aggregations

Element (com.zimbra.common.soap.Element)2 JSONElement (com.zimbra.common.soap.Element.JSONElement)2 XMLElement (com.zimbra.common.soap.Element.XMLElement)2 EnumElemList (com.zimbra.soap.jaxb.EnumElemList)2 ViewEnum (com.zimbra.soap.jaxb.ViewEnum)2 WrappedEnumElemList (com.zimbra.soap.jaxb.WrappedEnumElemList)2 FilterTest (com.zimbra.soap.mail.type.FilterTest)2 XmlAnyElement (javax.xml.bind.annotation.XmlAnyElement)2 XmlElement (javax.xml.bind.annotation.XmlElement)2 Test (org.junit.Test)2