Parameters order with and @XmlType(propOrder) and Resteasy jackson

筅森魡賤 提交于 2020-01-03 02:46:21

问题


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?


回答1:


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




回答2:


This is fixed with Jackson 2.3.2. Upgrade and your problems go away.



来源:https://stackoverflow.com/questions/7099030/parameters-order-with-and-xmltypeproporder-and-resteasy-jackson

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!