Skip to content
Advertisement

Jackson polymorphic serialization generates an incorrect class name

When I use Jackson polymorphic serialization, it generates a JSON object with an incorrect fully qualified class name.

The code below serializes an XMLGregorianCalendar. The output is:

JavaScript

I expected the following:

JavaScript

Why does it output java.util.GregorianCalendar?

Or more importantly: How do I fix this?

Code example:

JavaScript

Advertisement

Answer

To get the expected behavior I have implemented a custom XMLGregorianCalendar serializer. This class takes care of the serialization of the XLMGregorianCalendar and now the output is exactly what I expect. 🙂

JavaScript

You can add this serializer to the object mapper with the code below. It can be pasted in the code example in the question.

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement