Rename "type" from JSON moxy output

I'm struggling with the way how Moxy handles inheritance of objects.

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

This question relates to the Remove "type" from JSON output jersey moxy but unfortunately, it doesn't answer my question.

I have tried to include @XmlDiscriminatorNode on my abstract class which didn't seem to make any difference in the resulting json at all.

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


There has been change in handling of type property in MOXy 2.6. As of MOXy 2.6, type property is by default prefixed with xsi prefix (or whatever prefix you define). It means that there should be no type property clash in MOXy beginning with version 2.6.

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

Namespace prefix needs to be specified as 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);

链接地址: http://www.djcxy.com/p/25534.html

上一篇: 如何在bash脚本中提示用户进行确认?

下一篇: 从JSON moxy输出中重命名“type”