@JsonView to filter inputs to a consuming JAX-RS endpoint?

646 views
Skip to first unread message

Neil Mole

unread,
Oct 2, 2014, 7:05:15 PM10/2/14
to jackso...@googlegroups.com
A POJO uses @JsonView annotations with two different View identifier classes to determine which of the POJO's properties get returned from one of two JAX-RS endpoints - the endpoints being annotated with @JsonView referencing the same View classes.
This works great.

The POJOs are created using an endpoint which @Consumes(MediaType.APPLICATION_JSON) - a parameter of type POJO gets automatically populated with fields from the JSON in the HTTP POST body. Currently it seems that all properties that have the @JsonView annotation can be set, regardless of which View class they refer to.
I guess that the @JsonView annotation on the endpoint applies only to the response, not the input.

I would like to be able to filter so that some properties can't be set in the POST, is there a way I've missed to do this?


This is on JBoss Wildfly 8 which is using RestEasy.

Thanks
Neil

Tatu Saloranta

unread,
Oct 2, 2014, 7:14:21 PM10/2/14
to jackso...@googlegroups.com
Technically speaking Jackson can apply JSON View for deserialization too, but you are right this is not connected by Jackson JAX-RS provider.
The question is how this should be indicated. If JAX-RS passes annotations for actual parameter, we could do:

@JsonView(ViewForResponse.class)
public ResponseValue method(@JsonView(ViewForRequest.class) InputValue value) { /.... }

but I am not 100% sure if this is how things work (it might be that only method-annotations are passed; or perhaps combination of method and parameter ones).

If this does not work, it'd be necessary to add a new annotation type for Jackson JAX-RS provider (@JsonRequestView?).
This should be easy enough to do.
so this could be worked on for 2.5?

-+ Tatu +-


--
You received this message because you are subscribed to the Google Groups "jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jackson-user...@googlegroups.com.
To post to this group, send email to jackso...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Neil Mole

unread,
Oct 3, 2014, 5:49:01 AM10/3/14
to jackso...@googlegroups.com
Great, thanks.

Yes I agree, parameter annotation would be ideal if it works.

Created: https://github.com/FasterXML/jackson-jaxrs-providers/issues/57

Thanks!
Neil
Reply all
Reply to author
Forward
0 new messages