use of com.zimbra.soap.jaxb.WrappedEnumElemList in project zm-mailbox by Zimbra.
the class JaxbToJsonTest method wrappedEnumElemList.
/**
* Testing form:
* {@code @XmlElementWrapper(name="wrapper", required=false)
* @XmlElement(name="enum-entry", required=false)
* private List<ViewEnum> entries = Lists.newArrayList();}
* Desired JSON :
* {
* "wrapper": [{
* "enum-entry": [
* {
* "_content": "appointment"
* },
* {
* "_content": "document"
* }]
* }],
* "_jsns": "urn:zimbraTest"
* }
*/
@Test
public void wrappedEnumElemList() throws Exception {
Element jsonElem = JSONElement.mFactory.createElement(QName.get("wrapped-enum-elem-list", "urn:zimbraTest"));
Element wrapElem = jsonElem.addNonUniqueElement("wrapper");
wrapElem.addNonUniqueElement("enum-entry").addText(ViewEnum.APPOINTMENT.toString());
wrapElem.addNonUniqueElement("enum-entry").addText(ViewEnum.DOCUMENT.toString());
logDebug("JSONElement (for comparison) ---> prettyPrint\n%1$s", jsonElem.prettyPrint());
WrappedEnumElemList tstr = new WrappedEnumElemList();
tstr.addEntry(ViewEnum.APPOINTMENT);
tstr.addEntry(ViewEnum.DOCUMENT);
Element jsonJaxbElem = JacksonUtil.jaxbToJSONElement(tstr);
WrappedEnumElemList roundtripped = JaxbUtil.elementToJaxb(jsonJaxbElem, WrappedEnumElemList.class);
logDebug("JSONElement from JAXB ---> prettyPrint\n%1$s", jsonJaxbElem.prettyPrint());
Element wElem = jsonJaxbElem.getElement("wrapper");
List<Element> jsonElems = wElem.listElements();
List<ViewEnum> entries = roundtripped.getEntries();
Assert.assertEquals("jsonElems num", 2, jsonElems.size());
Assert.assertEquals("entries num", 2, entries.size());
Assert.assertTrue("has APPOINTMENT", entries.contains(ViewEnum.APPOINTMENT));
Assert.assertTrue("has DOCUMENT", entries.contains(ViewEnum.DOCUMENT));
}
Aggregations