Does MOXy support non-string @XmlID in version 2.6

2019-06-20 04:49发布

问题:

According to https://gist.github.com/VineetReynolds/5108580, JAXB Spec requires element annotated with @XmlID to be a String. This hasn't been enforced by MOXy in versions 2.5.x.
With version 2.6.0, however, it seems it's not supported anymore.

[Exception [EclipseLink-50016] (Eclipse Persistence Services - 2.6.0.v20150309-bf26070): org.eclipse.persistence.exceptions.JAXBException
Exception Description: Property [id] has an XmlID annotation but its type is not String.]**strong text**

Is this a wanted behavior, or an unwanted regression?

What is the right way to avoid such error when migrating from MOXy 2.5.x?
Is it to use @XmlJavaTypeAdapter as described in this post Marshaling a long primitive type using JAXB, which also affects the way how the object itself (and its ID) gets serialized to JSON (e.g., id field of type Long becomes a json string?

回答1:

Yes, it is still supported. In 2.6.0 it is not supported by default, but must be enabled via @XmlIDExtension annotation.

https://eclipse.org/eclipselink/releases/2.6.php

Just annotate given field with @XmlIDExtension. It is also possible to specify system property org.eclipse.persistence.moxy.annotation.xml-id-extension to override default behavior globally.