Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ProviderBase: JAX-WS controller http handler method returning a generic collection forces static type serialisation for that collection #73

Open
ylexus opened this issue Aug 14, 2015 · 3 comments

Comments

@ylexus
Copy link

ylexus commented Aug 14, 2015

Example:

class Controller {
    @GET 
    public Collection<MyClass> getCollection {
        return Arrays.<MyClass>asList(new SubclassOfMyClass())
    }
}

class MyClass {
    public getA() {
       ...
    }
}
class SubclassOfMyClass extends MyClass {
    public getB() {
       ...
    }
}

When used with Jersey's JacksonFeature, JSON returned will only contain attribute A and not attribute B because static serialisation of the root type is forced and there is no way I can override that. If, however, I wrap the collection with some other non-generic type, then static serialisation will not be forced and I will get both attribute "a" and "b" in the JSON produced by this GET.

jackson-jaxrs-base version used is 2.5.4.

Issue originally reported against Jersey but they are inclined to blame jackson: https://java.net/jira/browse/JERSEY-2939.

@cowtowncoder
Copy link
Member

This is a tricky problem, if I recall correctly, and I am not quite sure what to do with it.
My general advice at this point is to never use a generic type as root value, because of multiple related issues, with or without JAX-RS/JAX-WS. Beyond issue of static/dynamic content types, there is also the problem with polymorphism (for general case, hopefully not in your case).

But first things first: just to make sure, can this be reproduced with 2.6.1 as well?

@ylexus
Copy link
Author

ylexus commented Aug 17, 2015

This is how we worked around it, having something else wrapping the collection as a root value was better design anyway. To be honest, our problem is solved and I do not think I can spend much more time on this. I just thought it's something you may want to fix, but since it's complicated maybe documentation could explicitly warn users from doing it.

@cowtowncoder
Copy link
Member

@ylexus I appreciate your reporting this, and I agree that at very least it is worth commenting. It has been an on-going challenge as well, trying to balance sometimes conflicting needs. And finally, it is valuable to have issues filed for when others hit the same problem -- at least they can read more about problem itself, work-arounds and so forth.

I will keep this open for now, since there are some ideas for 2.7 that could help here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants