0

I am having a similar issue that's been discussed here: com.sun.istack.SAXException2: class java.util.LinkedHashMap nor any of its super class is known to this context

Basically: using JAXB, I want to serialize a 'complex' POJO that's been generated by XJC (and xsd schemas) to XML but the conversion fails with the error:

Caused by: javax.xml.bind.JAXBException: class java.util.LinkedHashMap nor any of its super class is known to this context.

The POJO is complex in the sense that it has fields with type List<Object> that in runtime gets instantiated to a List<LinkedHashMap<Category>>. Thus it appears that JAXB does not know how to convert this to XML.

When I add LinkedHashMap.class to the JAXB Context, the serialization succeeds but the xml is incomplete:

<response> <Common Version="1.1" Lang="EN"> <Option xsi:type="linkedHashMap"/> </Common> </response>

The <Common> node is incomplete because it is serializing Option but not Category.

Is this a known issue with JAXB? That it doesn't support serialization of LinkedHashMap data types?

Thank you.

Yaz
  • 17,126
  • 3
  • 16
  • 11
  • You could also use jackson for XML with `jackson-dataformat-xml jar` if that works for your case – Siddharth Trikha Oct 01 '19 at 17:40
  • Thank you @SiddarthTrikha. I will try it but I believe my issue is one of the limitations that they list: https://github.com/FasterXML/jackson-dataformat-xml – Yaz Oct 01 '19 at 18:32

0 Answers0