use of com.zimbra.soap.jaxb.EnumAttribs in project zm-mailbox by Zimbra.
the class JaxbToJsonTest method xmlEnumValuesInAttributes.
/**
* 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": "",
* "_jsns": "urn:zimbraTest"
* }
*/
@Test
public void xmlEnumValuesInAttributes() throws Exception {
EnumAttribs tstr = new EnumAttribs();
tstr.setFold1(ViewEnum.VIRTUAL_CONVERSATION);
tstr.setFold2(ViewEnum.UNKNOWN);
Element jsonJaxbElem = JacksonUtil.jaxbToJSONElement(tstr, QName.get("enum-tester", "urn:zimbraTest"));
EnumAttribs roundtripped = JaxbUtil.elementToJaxb(jsonJaxbElem, EnumAttribs.class);
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.getAttribute("fold2"));
Assert.assertEquals("roundtripped fold1", ViewEnum.VIRTUAL_CONVERSATION, roundtripped.getFold1());
Assert.assertEquals("roundtripped fold2", ViewEnum.UNKNOWN, roundtripped.getFold2());
}
use of com.zimbra.soap.jaxb.EnumAttribs in project zm-mailbox by Zimbra.
the class JaxbToJsonTest method elementRefsHandling.
/**
* XmlElementRefs handling
* Desired JSON :
* {
* "string-attr-int-value": [{
* "attr1": "my string",
* "_content": 321
* }],
* "enumEttribs": [{
* "fold1": "chat",
* "fold2": "remote folder"
* }],
* "_jsns": "urn:zimbraTest"
* }
*/
@Test
public void elementRefsHandling() throws Exception {
String str = "my string";
int num = 321;
List<Object> elems = Lists.newArrayList();
ElementRefsTester jaxb = new ElementRefsTester();
StringAttribIntValue inner = new StringAttribIntValue(str, num);
elems.add(inner);
EnumAttribs ea = new EnumAttribs();
ea.setFold1(ViewEnum.CHAT);
ea.setFold2(ViewEnum.REMOTE_FOLDER);
elems.add(ea);
jaxb.setElems(elems);
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());
ElementRefsTester roundtrippedX = JaxbUtil.elementToJaxb(xmlElem, ElementRefsTester.class);
ElementRefsTester roundtripped = JaxbUtil.elementToJaxb(jsonJaxbElem, ElementRefsTester.class);
Assert.assertEquals("roundtrippedX num elems", 2, roundtrippedX.getElems().size());
Assert.assertEquals("roundtripped num elems", 2, roundtripped.getElems().size());
StringAttribIntValue rtByRef = (StringAttribIntValue) roundtripped.getElems().get(0);
StringAttribIntValue rtXmlByRef = (StringAttribIntValue) roundtrippedX.getElems().get(0);
Assert.assertEquals("roundtrippedX str", str, rtXmlByRef.getAttrib1());
Assert.assertEquals("roundtrippedX num", num, rtXmlByRef.getMyValue());
Assert.assertEquals("roundtripped str", str, rtByRef.getAttrib1());
Assert.assertEquals("roundtripped num", num, rtByRef.getMyValue());
EnumAttribs rtea = (EnumAttribs) roundtripped.getElems().get(1);
Assert.assertEquals("roundtripped fold1", ViewEnum.CHAT, rtea.getFold1());
Assert.assertEquals("roundtripped fold2", ViewEnum.REMOTE_FOLDER, rtea.getFold2());
}
Aggregations