Jackson annotations ignored after deployment to JBOSS

谁说胖子不能爱 提交于 2019-12-24 13:33:52

问题


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

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