Skip to Content
0
Former Member
Mar 12, 2015 at 02:44 PM

Marshalling field of type Map[String, List[ComplexTypeWsDTO]] to XML with JAXB in OCCv2

530 Views

The generic OCCv2 TypeAdapter transforms the WsDTO objects to a corresponding XML representation. This works perfectly fine for all fields, except for fields with type Map>. The XML output looks as follows:

 <mapFieldName>
       <entry>
          <key>myKeyString</key>
          <value>com.company.hybris.occ.dto.ComplexTypeWsDTO@5f9f95c3 com.company.hybris.occ.dto.ComplexTypeWsDTO@66216640 com.company.hybris.occ.dto.ComplexTypeWsDTO@1ac02822</value>
       </entry>
 </mapFieldName>

The objects in the nested List get printed out using a simple toString representation.

How can I wrap the nested list in an additional XML tag and marshalling the inner classes fields? I would like to define the XML-Mapping for JAXB using a custom XML external binding declaration, that only affects specific Types, that contain those map-based fields. The default Hybris implementation uses TypeAdapters instead. The generic base class for mapping the fields to XML uses reflections to add the XML wrappers at runtime. I can't extend this class, because the type erasure mechanism of the jvm prohibits the retention of the key-value types of the field. I need an xml output as follows:

 <mapFieldName>
       <entry>
          <key>myKeyString</key>
          <value>
              <complexField1>object1Field1</complexField1>
              <complexField2>object1Field2</complexField2>
          </value>
          <value>
              <complexField1>object2Field1</complexField1>
              <complexField2>object2Field2</complexField2>
          </value>
          <value>
              <complexField1>object3Field1</complexField1>
              <complexField2>object3Field2</complexField2>
          </value>
       </entry>
 </mapFieldName>