Search in sources :

Example 1 with EnumAttribEnumElem

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

the class JaxbToJsonTest method missingRequiredEnumAttrib.

/**
 * Permissive handling - if required things are not present, users need to handle this
 */
@Test
public void missingRequiredEnumAttrib() throws Exception {
    EnumAttribEnumElem tstr = new EnumAttribEnumElem();
    // tstr.setFold1(ViewEnum.VIRTUAL_CONVERSATION);
    tstr.setFold2(ViewEnum.UNKNOWN);
    Element jsonJaxbElem = JacksonUtil.jaxbToJSONElement(tstr);
    EnumAttribEnumElem roundtripped = JaxbUtil.elementToJaxb(jsonJaxbElem, EnumAttribEnumElem.class);
    logDebug("JSONElement from JAXB ---> prettyPrint\n%1$s", jsonJaxbElem.prettyPrint());
    Assert.assertEquals("fold2 value", ViewEnum.UNKNOWN.toString(), jsonJaxbElem.getElement("fold2").getText());
    Assert.assertEquals("roundtripped fold1", null, roundtripped.getFold1());
    Assert.assertEquals("roundtripped fold2", ViewEnum.UNKNOWN, roundtripped.getFold2());
}
Also used : 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) EnumAttribEnumElem(com.zimbra.soap.jaxb.EnumAttribEnumElem) FilterTest(com.zimbra.soap.mail.type.FilterTest) Test(org.junit.Test)

Example 2 with EnumAttribEnumElem

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

the class JaxbToJsonTest method xmlEnumValuesInAttrAndElem.

/**
 * If you just use a pair of annotation introspectors (JacksonAnnotationIntrospector/JaxbAnnotationIntrospector)
 * then "XmlEnumValue"'s are ignored - AnnotationIntrospector.Pair's findEnumValue(Enum<?> e) method won't
 * call the secondary's findEnumValue unless primary's findEnumValue returns null.
 * (if we made JaxbAnnotationIntrospector the primary, this would work but other things wouldn't)
 * To fix this, the current code makes use of ZmPairAnnotationIntrospector which overrides findEnumValue
 * Desired JSON :
 *     {
 *       "fold1": "virtual conversation",
 *       "fold2": [{
 *           "_content": ""
 *         }],
 *       "_jsns": "urn:zimbraTest"
 *     }
 */
@Test
public void xmlEnumValuesInAttrAndElem() throws Exception {
    Element jsonElem = JSONElement.mFactory.createElement(QName.get("enum-tester", "urn:zimbraTest"));
    jsonElem.addAttribute("fold1", ViewEnum.VIRTUAL_CONVERSATION.toString());
    jsonElem.addNonUniqueElement("fold2").addText(ViewEnum.UNKNOWN.toString());
    EnumAttribEnumElem tstr = new EnumAttribEnumElem();
    tstr.setFold1(ViewEnum.VIRTUAL_CONVERSATION);
    tstr.setFold2(ViewEnum.UNKNOWN);
    Element jsonJaxbElem = JacksonUtil.jaxbToJSONElement(tstr, QName.get("enum-tester", "urn:zimbraTest"));
    EnumAttribEnumElem roundtripped = JaxbUtil.elementToJaxb(jsonJaxbElem, EnumAttribEnumElem.class);
    logDebug("JSONElement (for comparison) ---> prettyPrint\n%1$s", jsonElem.prettyPrint());
    logDebug("JSONElement from JAXB ---> prettyPrint\n%1$s", jsonJaxbElem.prettyPrint());
    // Want 'virtual conversation' not 'VIRTUAL_CONVERSATION'
    Assert.assertEquals("fold1 value", ViewEnum.VIRTUAL_CONVERSATION.toString(), jsonJaxbElem.getAttribute("fold1"));
    // Want '' not 'UNKNOWN'
    Assert.assertEquals("fold2 value", ViewEnum.UNKNOWN.toString(), jsonJaxbElem.getElement("fold2").getText());
    Assert.assertEquals("roundtripped fold1", ViewEnum.VIRTUAL_CONVERSATION, roundtripped.getFold1());
    Assert.assertEquals("roundtripped fold2", ViewEnum.UNKNOWN, roundtripped.getFold2());
}
Also used : 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) EnumAttribEnumElem(com.zimbra.soap.jaxb.EnumAttribEnumElem) 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 EnumAttribEnumElem (com.zimbra.soap.jaxb.EnumAttribEnumElem)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