Jersey/JAX-RS : How to cascade beans-validation recursively with @Valid automatically?

Actually, according to the specification, adding @Valid is exactly for this usecase. From the JSR 303 specification: In addition to supporting instance validation, validation of graphs of object is also supported. The result of a graph validation is returned as a unified set of constraint violations. Consider the situation where bean X contains a field … Read more

Jersey + Jackson JSON date format serialization – how to change the format or use custom JacksonJsonProvider

I managed to do it in Resteasy “the JAX-RS way”, so it should work on every compliant implementation like Jersey (recently successfully tested on JEE7 server Wildfly 8, it just required a few changes to the Jackson part because they changed a few APIs). You must define a ContextResolver (check that Produces contains the correct … Read more

How to return a partial JSON response using Java?

If you use Jackson (a great JSON lib – kind of the standard for Java I believe), you may use the @View annotation to filter what you want in the resulting object. I understand that you want something dynamic so it’s a bit more complicated. You will find what you are looking for here: http://www.cowtowncoder.com/blog/archives/2011/02/entry_443.html … Read more

What objects can I inject using the @Context annotation?

The @Context annotation allows you to inject request/response context details into JAX-RS provider and resource classes. Injection can be performed into a class field, a bean property or a method parameter. The following list summarizes all the types that can be injected using the @Context annotation, according to the JAX-RS 2.0 specification: javax.ws.rs.core.Application javax.ws.rs.core.HttpHeaders javax.ws.rs.core.Request … Read more

Optional @PathParam in Jax-RS

The problem was the lack of whitespace before the colon: @Path(“/mypath{param1: (/param1)?}”) should be: @Path(“/mypath{param1 : (/param1)?}”) Apparently it’s a bug, because the specification makes the whitespace around the colon optional. I also found that I’m not the first bitten by this bug.

Design Pattern to model Request and Response Objects for Webservices

The big problem I see in all the answers so far including the question is that they all violate the principal of separation of concerns, information hiding and encapsulation. In all answers request (and response) classes are tightly coupled to model classes. That is a more serious issue and raises a question more important than … Read more