Ignore fields from Java object dynamically while sending as JSON from Spring Boot

Ignore fields from Java object dynamically while sending as JSON from Spring Boot


I don't want uptoTimeIndex and chunkSize to be available 

Add the annotation @JsonIgnoreProperties("fieldname") to your POJO.
or you can use @JsonIgnore also before field name that you want to ignore while deserializing json.

public class TimeLogData implements Serializable {

    private List  data;    public Long uptoTimeIndex = 0L;    public Integer chunkSize = 0;
    public List getData() {
        return data;    }

    public void setData(List data) {
        this.data = data;    }

    public void setUptoTimeIndex(Long uptoTimeIndex) {
        this.uptoTimeIndex = uptoTimeIndex;    }

    public void setChunkSize(Integer chunkSize) {
        this.chunkSize = chunkSize;    }

    @JsonIgnore    public Long getUptoTimeIndex() {
        return uptoTimeIndex;    }

    @JsonIgnore    public Integer getChunkSize() {
        return chunkSize;    }
}



No comments:

 My Attempt to learn AI  GPT Generative Pretrained Transformer Created by Google in 2017 with the publication of the paper "Attention ...

Popular in last 30 days