Is is possible to exclude JsonProperties
in the output of a Spring Boot Rest call based on a defined condition? (eg. the role of the user)
Example:
public class Employee{
@JsonProperty
private String name;
@JsonProperty
private String fieldForManagerOnly;
@JsonProperty
private String fieldForEmployeeOnly;
}
I want to have the fieldForManagerOnly
only serialized in the JSON output when the user has the ROLE manager
.
I've already tried the solution with the @JsonView
(as described in Latest Jackson integration improvements in Spring) but that solution is very limited as the @JsonView
is bound to one controler method and I want to have only one controller method.