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());
}
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());
}
Aggregations