Annotation for binding a json field to a field in POJO with a different name

前端 未结 2 664
感动是毒
感动是毒 2021-01-25 06:05

Java class (used as a Data Transfer Object):

class Resource also has a field named id with a different type along with its getter and setter, hence the synt

2条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-25 06:56

    public A extends Resource {
        private int id;
    
        @JsonProperty("_id")
        public int getId() {
          return id;
        }
    
        @JsonProperty("id")
        public void setId(int id) {
          this.id = id;
        }
    }
    

    the method names should be different, so jackson parses it as different fields, not as one field.

提交回复
热议问题