users@jersey.java.net

[Jersey] Re: Issue with JsonView and async methods

From: Marek Potociar <marek.potociar_at_oracle.com>
Date: Mon, 29 Apr 2013 18:55:11 +0200

Thanks for the report Andrzej. Would you mind filing this as a new bug in our Jira?
https://java.net/jira/browse/jersey

Marek

On Apr 26, 2013, at 1:23 PM, andrzej.leskiewicz_at_gmail.com wrote:

> Hello,
>
> I came upon ana interesting problem with using @JsonView annotation
> with asynchronous responses from server. I've created a sample
> application in github where You can reproduce it. Project is available
> here: https://github.com/aleskiewicz/AsycJsonView
>
>
> The Problem:
> I'm using @JsonView annotation to change serialization rules on result
> of a REST call to my applicaiton (as described here
> http://jira.codehaus.org/browse/JACKSON-578)
> I have a class with 3 attributes, one visible in all views, and two
> visible in separate views (WebView and DetailsWebView respectively).
> I have an endpoint with 3 methods, 2 for GET requests and one for POST.
> Synchronous GET and POST request are working fine. Asynchronous request
> gets interesting, because depending on situation I can get two types of
> answer:
> 1. Valid answer with information from specified JsonView
> 2. Invalid answer with all fields of object serialized.
>
> First case is when I call AsyncResponse.resume after initial GET call
> (asynchronous method in Resource ends).
> Latter case is when I call AsyncResponse.resume during this call
> (inside the asynchronous method in Resource).
>
> Hack solutions:
> There are two ways to resolve this
> 1. (VERY UGGLY) Call AsyncResponse.resume in separate thread, after
> asynchronous method in Resource ends
> 2. (UGGLY) Pack javax.ws.rs.core.Response into
> org.glassfish.jersey.message.internal.OutboundJaxrsResponse and call
> setEntityAnnotations with annotations from enpoint method.
>
> I know these are not elegant, but maybe it can lead You guys to real
> solution.
>
> --
> best regards
> Andrzej Leśkiewicz