问题
I have a class which uses two Jackson annotations:
@JsonIgnoreProperties(ignoreUnknown = true)
public class MyObject{
@JsonProperty(value = "fooVal")
private String foo;
public MyObject(){}
public String getFoo() {
return foo;
}
public void setFoo(String foo) {
this.foo = foo;
}
}
When I use the ObjectMapper
to map the recieved JSON to MyObject
on a local enviroment in a test case it works without problems, however if I deploy the module to my JBOSS AS all the annotations are being ignored and I can't figure out why.
My pom.xml
has the dependency:
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
</dependency>
So the library is imported into the WAR folder in deployments.
Why are the annotations ignored after deployment please?
回答1:
The problem was in library conflicts due to autoimporting of an older version of Jackson. The solution was to include:
<exclusions>
<module name="org.codehaus.jackson.jackson-core-asl" />
<module name="org.codehaus.jackson.jackson-mapper-asl" />
</exclusions>
Into jboss-deployment-structure.xml
in the deployment tag.
Important tip for other developers: When using a new library take into consideration your application server's firstclass/lastclass(classloading order preference) setting: WebSphere, Tomcat, JBOSS
来源:https://stackoverflow.com/questions/20683843/jackson-annotations-ignored-after-deployment-to-jboss