user2054927
user2054927

Reputation: 1011

Partial response in Spring MVC

Our RESTful application need to support 'partial responses' to limit bandwith. By this I mean that the REST client tells the URI service which fields of the resource it is interested in.

For instance: api/v1/users/123/fields=firstName,lastName,birthDate

We're using Jackson parser to convert our DTO's to a JSON structure. The problem is that we cannot tell at runtime to 'skip' some properties. We should need to create a class at runtime with a variable amount of properties to accomplish this. But I don't think this is possible in Java, it is a static language after all.

While searching the internet we found some semi-solutions by just returning a java.util.Map containing the requested properties or filtering out properties by the Jackson parser. Especially the latter seems a 'hacking solution' to me. It seems that Spring MVC doesn't provide an out-of-the-box solution for this issue...

Is there any alternative in the Java world we can use to solve this issue?

Upvotes: 4

Views: 2926

Answers (1)

theon
theon

Reputation: 14390

How about Yoga

Yoga extends JAX-RS and SpringMVC RESTful servers to provide GData and LinkedIn style field selectors.

  • Choose which fields you want to see at call-time
  • Navigate entity relationships in a single call for complex views
  • Much faster speeds in high-latency (e.g. mobile) apps
  • Streamline client development
  • Browsable APIs

Upvotes: 2

Related Questions