I have an entity (using lombok) with some annotated @JsonView annotation.
@Entity
@Table(name = "`order`")
@Getter
@Setter
@ToString
@Description("Приказ")
public class Order extends Auditable {
private static final long serialVersionUID = -1299630493411381582L;
@JsonView(JsonViews.OrderAdvancedSearch.class)
@ManyToOne
private School school;
@Column(length = 50)
private String number;
}
There's a controller method annotated with @JsonView annotation.
@Secured(value = {"ROLE_AUTHENTICATED_USER"})
@RequestMapping(value = "/order", method = RequestMethod.GET, headers = {"Content-Type=application/json"})
@JsonView(JsonViews.OrderAdvancedSearch.class)
@ResponseBody
public ResponseEntity<Order> getOrder(HttpServletRequest request) throws IOException, DnevnikException, RestException {
Order order = orderRepository.findOne(292L); // just for example
return new ResponseEntity<>(order,HttpStatus.OK);
}
I've expected that input will contain only fields annotated with @JsonView. But I've full of fields.
I'm trying to debug spring and jackson sources. In com.fasterxml.jackson.databind.SerializationConfig I see that active view is my class JsonViews.OrderAdvancedSearch.class But in com.fasterxml.jackson.databind.ser.std.BeanSerializerBase variable filteredProps always has all properties of my entity.
Try to tweak your Jackson object mapper:
// disable this feature so that attributes with no view definition
// do not get serialized / deserialized
mapper.disable(MapperFeature.DEFAULT_VIEW_INCLUSION);
Reference: Feature: JSON Views
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With