Rename JSON fields used by MappingJacksonJsonView in Spring

后端 未结 2 656
爱一瞬间的悲伤
爱一瞬间的悲伤 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();
    
      //...
    
    0 讨论(0)
  • 2021-01-01 19:04

    Have you tried using the @JsonProperty annotation?

    "Defines name of the logical property, i.e. Json object field name to use for the property: if empty String (which is the default), will use name of the field that is annotated."

    0 讨论(0)
提交回复
热议问题