Jackson renames primitive boolean field by removing 'is'

后端 未结 10 839
渐次进展
渐次进展 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 12:41

    I recently ran into this issue and this is what I found. Jackson will inspect any class that you pass to it for getters and setters, and use those methods for serialization and deserialization. What follows "get", "is" and "set" in those methods will be used as the key for the JSON field ("isValid" for getIsValid and setIsValid).

    public class JacksonExample {   
    
        private boolean isValid = false;
    
        public boolean getIsValid() {
            return isValid;
        }
    
        public void setIsValid(boolean isValid) {
            this.isValid = isValid;
        }
    } 
    

    Similarly "isSuccess" will become "success", unless renamed to "isIsSuccess" or "getIsSuccess"

    Read more here: http://www.citrine.io/blog/2015/5/20/jackson-json-processor

提交回复
热议问题