和@XmlType(propOrder)和Resteasy jackson的参数顺序 [英] Parameters order with and @XmlType(propOrder) and Resteasy jackson

查看:68
本文介绍了和@XmlType(propOrder)和Resteasy jackson的参数顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用resteasy生成json. 一切正常,但是...我无法订购生成的json的参数:

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"})

在生成的json中,我得到:

in my generated json, i get:

{"foo2":"bar2","foo1":"bar1","foo3":""}

我的pom.xml中存在以下依赖项

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>

有什么主意吗?

推荐答案

一个简单的答案是没关系"-JSON Object中属性的顺序没有意义,因此库和框架可以自由地将其输出他们想要什么顺序.

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.

但更复杂的答案可能是尝试使用杰克逊自己的 @JsonPropertyOrder 注释,该注释应该起作用.除非您绝对必须使用JAXB批注,否则可能会解决您的问题.

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.

即使如此,启用JAXB注释模式时,Jackson也应支持此JAXB注释.因此,如果需要使用JAXB批注,则需要尝试弄清楚为什么未启用支持. RESTeasy可能启用或未启用它,因为Jackson本身默认情况下不使用它们(即框架必须显式启用它).

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).

这篇关于和@XmlType(propOrder)和Resteasy jackson的参数顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆