I have a POJO class which has the annotation @JsonInclude(Include.NON_NULL)
for the class.
@JsonInclude(Include.NON_NULL)
@Getter
@Setter
public class Attribute implements Serializable {
private String type;
private List<Object> value;
private String unit;
private List<Object> metaInfo;
}
and controller looks like this.
@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
public Attribute getSingle() {
return getAttribute(); // getAttribute() will get the object of type Attribute.
}
Now, I have a requirement where based on the value of type field, need to return null for value field in the final JSON generated.
For example, if type='XYZ' the response will be { type:'XYZ'}
. And if type='ABC', then response should be { type:'ABC',value:null}
How can I achieve this in Spring boot? Whats the best way to handle these kind of scenarios?