美文网首页
Jackson renames primitive boolea

Jackson renames primitive boolea

作者: 带着二娃去遛弯 | 来源:发表于2019-03-19 10:11 被阅读0次

    This is a slightly late answer, but may be useful for anyone else coming to this page.

    A simple solution to changing the name that Jackson will use for when serializing to JSON is to use the @JsonProperty annotation, so your example would become:

    public class MyResponse implements Serializable {
    
        private boolean isSuccess;
    
        @JsonProperty(value="isSuccess")        
        public boolean isSuccess() {
            return isSuccess;
        }
    
        public void setSuccess(boolean isSuccess) {
            this.isSuccess = isSuccess;
        }
    }
    

    This would then be serialised to JSON as {"isSuccess":true}, but has the advantage of not having to modify your getter method name.

    Note that in this case you could also write the annotation as @JsonProperty("isSuccess") as it only has the single value elemen

    相关文章

      网友评论

          本文标题:Jackson renames primitive boolea

          本文链接:https://www.haomeiwen.com/subject/jtnwmqtx.html