Jackson Not Overriding Getter with @JsonProperty

If using Kotlin

I understand the original question is in Java, but since Kotlin is becoming very popular and many might be using it I'd like to post this here to help others.

Anyway, for Kotlin, because how getters/setters work, if you are using val, meaning you only expose the getter, you may need to apply the annotation to the getter like below:

class JacksonTester(@get:JsonProperty("hello") val hi: String)


The problem was that I was using both the old and new jackson libraries

i.e. before I had import org.codehaus.jackson.annotate.JsonProperty; Which I had to change to below, to be consistent with the library I was using.

Since I was using maven that also meant updating my maven dependencies. import com.fasterxml.jackson.annotation.JsonProperty;

For it to work, I needed the @JsonProperty annotation on the getter (putting it on the object didn't work)

I found the answer here (thanks to francescoforesti) @JsonProperty not working as expected


I know its an old question but for me I got it working when I figured out that its conflicting with Gson library so I had to use @SerializedName("name") instead of @JsonProperty("name") hope this helps


I had this problem when updating from older version to 2.8.3 of FasterXML Jackson.

The issue was when deserializing the JSON response from our DB into Java class object, our code didn't have @JsonSetter on the class' setters. Hence, when serializing, the output wasn't utilizing the class' getters to serialize the Java class object into JSON (hence the @JsonProperty() decorator wasn't taking effect).

I fixed the issue by adding @JsonSetter("name-from-db") to the setter method for that property.

Also, instead of @JsonProperty(), to rename properties using the getter method, you can and should use @JsonGetter() which is more specific to renaming properties.

Here's our code:

public class KwdGroup {
    private String kwdGroupType;

    // Return "type" instead of "kwd-group-type" in REST API response
    @JsonGetter("type") // Can use @JsonProperty("type") as well
    public String getKwdGroupType() {
        return kwdTypeMap.get(kwdGroupType);
    }

    @JsonSetter("kwd-group-type") // "kwd-group-type" is what JSON from the DB API outputs for code to consume 
    public void setKwdGroupType(String kwdGroupType) {
        this.kwdGroupType = kwdGroupType;
    }
}