oroblam
oroblam

Reputation: 109

Jackson ignoring annotation on dependency class

I'm trying to serialise a class that belongs to project B from project A using jackson. Since this class has some funny method names I needed to use MixIn annotation to make it serialisable from project A. That worked well, but later I was asked to make this change directly into project B, since we want many other projects to be able to serialise/deserialise this class.

I ended up putting annotation directly into the class, so my class became

public class Dog {

public Dog(@JsonProperty("breed") String colour) {
    this.colour = colour;
}
@JsonProperty("breed")
private String colour;
}

This is just an example and it shows what the class looks like. The point here is, when I serialise/deserialise the class inside project B the annotations are picked up and everything works as expected, whilst when I serialise/deserialise inside project A (that has project B as a dependency) the annotations are ignored. Does anybody know why this is happening?

Upvotes: 0

Views: 407

Answers (2)

MagGGG
MagGGG

Reputation: 20976

The first thing to do is to upgrade jars. New Maven dependencies are:

   <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-annotations</artifactId>
        <version>2.7.2</version>
        <type>jar</type>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>2.7.3</version>
    </dependency> 
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.7.2</version>
        <type>jar</type>
    </dependency>

You can make annotation work with usings different version but it it too much overhead and do not brings any advantages.

see:

org.codehaus.jackson versus com.fasterxml.jackson.core

http://wiki.fasterxml.com/JacksonUpgradeFrom19To20

Upvotes: 1

oroblam
oroblam

Reputation: 109

The problem was in the jackson version. Project B was using org.codehaus.jackson annotation, whilst project A was using com.fasterxml.jackson fasterxml.jackson ignores codehaus annotation.

Upvotes: 0

Related Questions