参数顺序与 @XmlType(propOrder) 和 Resteasy jackson
我使用resteasy 生成json。 一切正常,但是...我无法订购生成的 json 的参数:
在我的序列化类中,我有以下注释:
@XmlRootElement
@XmlType(propOrder={"foo1", "foo2", "foo3"})
在生成的 json 中,我得到:
{"foo2":"bar2","foo1":"bar1","foo3":""}
我的 pom.xml 中有以下依赖
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson-provider</artifactId>
<version>2.2.0.GA</version>
</dependency>
项?
I produce json using resteasy.
Everything works fine but... I can't order the parameters of my generated json:
In my serialized class, I have the following anotations:
@XmlRootElement
@XmlType(propOrder={"foo1", "foo2", "foo3"})
in my generated json, i get:
{"foo2":"bar2","foo1":"bar1","foo3":""}
There is the following dependency in my pom.xml
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson-provider</artifactId>
<version>2.2.0.GA</version>
</dependency>
any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一个简单的答案是“没关系”——JSON 对象中属性的排序没有意义,因此库和框架可以自由地按照他们想要的任何顺序输出它们。
但更复杂的答案可能是尝试使用 Jackson 自己的 @JsonPropertyOrder 注释,这应该可行。除非您绝对必须使用 JAXB 注释,否则这可能会解决您的问题。
即便如此,当启用 JAXB 注释模式时,Jackson 应该支持此 JAXB 注释。因此,如果您需要使用JAXB注释,您需要尝试找出为什么不启用支持。它可能会也可能不会通过 RESTeasy 启用,因为 Jackson 本身默认情况下不使用它们(即框架必须显式启用)。
A simple answer is that "it does not matter" -- ordering of properties in JSON Object has no significance, so libraries and frameworks are free to output them in whatever order they want to.
But more complex answer would be along lines of trying to maybe use Jackson's own @JsonPropertyOrder annotation, which should work. Unless you absolutely must use JAXB annotations, that might solve your problem.
Even so, this JAXB annotation should be supported by Jackson, when JAXB annotation mode is enabled. So if you need to use JAXB annotations, you need to try to figure out why support is not enabled. It may or may not be enabled with RESTeasy, since Jackson itself does not use them by default (i.e. framework has to explicitly enable then).
Jackson 2.3.2 已修复此问题。升级后您的问题就会消失。
This is fixed with Jackson 2.3.2. Upgrade and your problems go away.