Jackson Not Overriding Getter with @JsonProperty

前端 未结 10 2109
醉话见心
醉话见心 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:47

    Have you tried below

    class JacksonTester {
        private String hi;
    
        @JsonProperty("hello")
        public String getHi() {
            return hi;
        }
    }   
    

    I mean making the 'hi' variable declaration as private. Alternatively try to put a @JsonIgnore on the variable declaration and in case you would rather keep it at default scope.

提交回复
热议问题