本文介绍了MOXy在2.6.0版本中是否支持非字符串@XmlID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据,JAXB Spec要求使用 @XmlID 注释的元素为 String 。 MOXy未在 2.5.x 版本中强制执行此操作。

但是,对于版本 2.6.0 ,它似乎不再受支持了。

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?

从MOXy 2.5.x 迁移时避免此类错误的正确方法是什么?

是否使用 @XmlJavaTypeAdapter ,如本文所述,这也影响对象本身(及其ID)序列化为JSON的方式(例如,类型为 long的id字段成为json字符串?

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?

推荐答案

是的,它是stil我支持。在2.6.0中,默认情况下不支持,但必须通过 @XmlIDExtension 注释启用。

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

只需使用 @XmlIDExtension 注释给定字段。也可以指定系统属性 org.eclipse.persistence.moxy.annotation.xml-id-extension 以全局覆盖默认行为。

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.

这篇关于MOXy在2.6.0版本中是否支持非字符串@XmlID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 16:03