use of com.zimbra.soap.mail.type.DispositionAndText in project zm-mailbox by Zimbra.
the class JaxbToJsonTest method XmlValueAnnotation.
/**
* XmlValue should map to an attribute with name "_content"
* At present, classes that want this feature need the annotation @JsonProperty("_content"),
* otherwise, the name "value" is used.
* "chunk": [ { "disp": "disposition 1", "_content": "text 1\nIn the sun" },
* { "disp": "disPosition 2", "_content": "text 2" }],
*/
@Test
public void XmlValueAnnotation() throws Exception {
String dispos1 = "disposition 1";
String text1 = "text 1\nIn the sun";
String dispos2 = "disPosition 2";
String text2 = "text 2";
// --------------------------------- For Comparison - Element handling where the JAXB has an @XmlValue
Element legacyElem = JSONElement.mFactory.createElement(MailConstants.DIFF_DOCUMENT_RESPONSE);
legacyElem.addElement(MailConstants.E_CHUNK).addAttribute(MailConstants.A_DISP, dispos1).setText(text1);
legacyElem.addElement(MailConstants.E_CHUNK).addAttribute(MailConstants.A_DISP, dispos2).setText(text2);
logDebug("DiffDocumentResponse JSONElement ---> prettyPrint\n%1$s", legacyElem.prettyPrint());
// --------------------------------- @XmlValue handling test - need @JsonProperty("_content") annotation
DiffDocumentResponse ddResp = new DiffDocumentResponse();
ddResp.addChunk(DispositionAndText.create(dispos1, text1));
ddResp.addChunk(DispositionAndText.create(dispos2, text2));
Element jsonJaxbElem = JacksonUtil.jaxbToJSONElement(ddResp);
logDebug("DiffDocumentResponse JSONElement from JAXB ---> prettyPrint\n%1$s", jsonJaxbElem.prettyPrint());
List<Element> chunks = jsonJaxbElem.listElements();
Assert.assertEquals("Number of child elements", 2, chunks.size());
Element chunk1 = chunks.get(0);
Element chunk2 = chunks.get(1);
Assert.assertEquals("1st chunk disposition", dispos1, chunk1.getAttribute(MailConstants.A_DISP));
Assert.assertEquals("1st chunk value", text1, chunk1.getText());
Assert.assertEquals("2nd chunk disposition", dispos2, chunk2.getAttribute(MailConstants.A_DISP));
Assert.assertEquals("2nd chunk value", text2, chunk2.getText());
DiffDocumentResponse roundtripped = JaxbUtil.elementToJaxb(jsonJaxbElem, DiffDocumentResponse.class);
List<DispositionAndText> rtChunks = roundtripped.getChunks();
Assert.assertEquals("Number of roundtripped chunks", 2, rtChunks.size());
DispositionAndText rtChunk1 = rtChunks.get(0);
DispositionAndText rtChunk2 = rtChunks.get(1);
Assert.assertEquals("1st roundtripped chunk disposition", dispos1, rtChunk1.getDisposition());
Assert.assertEquals("1st roundtripped chunk value", text1, rtChunk1.getText());
Assert.assertEquals("2nd roundtripped chunk disposition", dispos2, rtChunk2.getDisposition());
Assert.assertEquals("2nd roundtripped chunk value", text2, rtChunk2.getText());
}
use of com.zimbra.soap.mail.type.DispositionAndText in project zm-mailbox by Zimbra.
the class JaxbToJsonTest method xmlValueAnnotation.
/**
* XmlValue should map to an attribute with name "_content"
* At present, classes that want this feature need the annotation @JsonProperty("_content"),
* otherwise, the name "value" is used.
* "chunk": [ { "disp": "disposition 1", "_content": "text 1\nIn the sun" },
* { "disp": "disPosition 2", "_content": "text 2" }],
*/
@Test
public void xmlValueAnnotation() throws Exception {
String dispos1 = "disposition 1";
String text1 = "text 1\nIn the sun";
String dispos2 = "disPosition 2";
String text2 = "text 2";
// --------------------------------- For Comparison - Element handling where the JAXB has an @XmlValue
Element legacyElem = JSONElement.mFactory.createElement(MailConstants.DIFF_DOCUMENT_RESPONSE);
legacyElem.addNonUniqueElement(MailConstants.E_CHUNK).addAttribute(MailConstants.A_DISP, dispos1).setText(text1);
legacyElem.addNonUniqueElement(MailConstants.E_CHUNK).addAttribute(MailConstants.A_DISP, dispos2).setText(text2);
logDebug("DiffDocumentResponse JSONElement ---> prettyPrint\n%1$s", legacyElem.prettyPrint());
// --------------------------------- @XmlValue handling test - need @JsonProperty("_content") annotation
DiffDocumentResponse ddResp = new DiffDocumentResponse();
ddResp.addChunk(DispositionAndText.create(dispos1, text1));
ddResp.addChunk(DispositionAndText.create(dispos2, text2));
Element jsonJaxbElem = JacksonUtil.jaxbToJSONElement(ddResp);
logDebug("DiffDocumentResponse JSONElement from JAXB ---> prettyPrint\n%1$s", jsonJaxbElem.prettyPrint());
List<Element> chunks = jsonJaxbElem.listElements();
Assert.assertEquals("Number of child elements", 2, chunks.size());
Element chunk1 = chunks.get(0);
Element chunk2 = chunks.get(1);
Assert.assertEquals("1st chunk disposition", dispos1, chunk1.getAttribute(MailConstants.A_DISP));
Assert.assertEquals("1st chunk value", text1, chunk1.getText());
Assert.assertEquals("2nd chunk disposition", dispos2, chunk2.getAttribute(MailConstants.A_DISP));
Assert.assertEquals("2nd chunk value", text2, chunk2.getText());
DiffDocumentResponse roundtripped = JaxbUtil.elementToJaxb(jsonJaxbElem, DiffDocumentResponse.class);
List<DispositionAndText> rtChunks = roundtripped.getChunks();
Assert.assertEquals("Number of roundtripped chunks", 2, rtChunks.size());
DispositionAndText rtChunk1 = rtChunks.get(0);
DispositionAndText rtChunk2 = rtChunks.get(1);
Assert.assertEquals("1st roundtripped chunk disposition", dispos1, rtChunk1.getDisposition());
Assert.assertEquals("1st roundtripped chunk value", text1, rtChunk1.getText());
Assert.assertEquals("2nd roundtripped chunk disposition", dispos2, rtChunk2.getDisposition());
Assert.assertEquals("2nd roundtripped chunk value", text2, rtChunk2.getText());
}
Aggregations