Jackson renames primitive boolean field by removing 'is'

后端 未结 10 834
渐次进展
渐次进展 2020-11-27 12:07

This might be a duplicate. But I cannot find a solution to my Problem.

I have a class

public class MyResponse implements Serializable {

    private          


        
10条回答
  •  忘掉有多难
    2020-11-27 13:00

    I didn't want to mess with some custom naming strategies, nor re-creating some accessors.
    The less code, the happier I am.

    This did the trick for us :

    import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
    import com.fasterxml.jackson.annotation.JsonProperty;
    
    @JsonIgnoreProperties({"success", "deleted"}) // <- Prevents serialization duplicates 
    public class MyResponse {
    
        private String id;
        private @JsonProperty("isSuccess") boolean isSuccess; // <- Forces field name
        private @JsonProperty("isDeleted") boolean isDeleted;
    
    }
    

提交回复
热议问题