Jackson Not Overriding Getter with @JsonProperty

前端 未结 10 2087
醉话见心
醉话见心 2021-02-12 06:23

JsonProperty isn\'t overriding the default name jackson gets from the getter. If I serialize the class below with ObjectMapper and jackson I get

<
10条回答
  •  失恋的感觉
    2021-02-12 06:39

    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

提交回复
热议问题