I think the @JsonView annotation will do for you.
You can read more here.
As an alternative, you can hang up the @JsonFilter annotation above your entity class. For example:
@JsonFilter("contract") public class SupplierContract
And in the controller class in the method:
public ResponseEntity<String> getSerializableData(Object data) throws JsonProcessingException { ObjectMapper objectMapper = new ObjectMapper(); String filter = "contract"; String[] except = new String[]{"excluded", "fields"}; SimpleFilterProvider provider = new SimpleFilterProvider().addFilter(filter, SimpleBeanPropertyFilter.serializeAllExcept(except)); return new ResponseEntity<>(objectMapper.writer(provider).writeValueAsString(data), HttpStatus.OK); }
In this case, all fields specified in the except array will be excluded from json for the filter "contract"