Rename JSON fields used by MappingJacksonJsonView in Spring

后端 未结 2 777
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-01 18:53

I\'m using MappingJacksonJsonView to serialize to JSON a class, however, I\'d like to be able to rename some of the fields from the default name based on the getter name.

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-01 19:02

    You should be able to qualify using @JsonProperty.

    @JsonAutoDetect(getterVisibility = Visibility.NONE)
    public interface Picture {
    
      @JsonSerialize
      @JsonProperty("name")
      String getName();
    
      @JsonSerialize
      @JsonProperty("delete_url")
      String getDeleteUrl();
    
      //...
    

提交回复
热议问题