Rename Type to Moxy JSON

I struggle with how Moxy handles object inheritance.

In particular, I need to rename the default type element, which Moxy adds in the case of subtypes, since it prevents me from having my own type field in my objects.

This question relates to Remove "type" from JSON output jersey moxy , but unfortunately it does not answer my question.

I tried to include @XmlDiscriminatorNode in my abstract class, which seems to have nothing to do with the resulting json at all.

I also tried to completely remove the default moxy type element, but without any success.

+7
java json marshalling eclipselink moxy
source share
1 answer

In MOXy 2.6, there have been changes to the processing of the type property. Starting with MOXy 2.6, the type property defaults to the xsi prefix (or any prefix you define). This means that in MOXy there should not be a conflict of type properties starting from version 2.6.

Details can be found at https://wiki.eclipse.org/EclipseLink/DesignDocs/459464

The namespace prefix must be specified as a JAXBContext property:

unmarshaller.setProperty (JAXBContextProperties.MEDIA_TYPE, MediaType.APPLICATION_JSON); Map namespaces = new HashMap <> (); namespaces.put (javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "xsi"); unmarshaller.setProperty (JAXBContextProperties.NAMESPACE_PREFIX_MAPPER, namespaces);

+3
source share

All Articles