问题
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