Jackson renames primitive boolea

2019-03-19  本文已影响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

上一篇下一篇

猜你喜欢

热点阅读