I'd like to explain what Marek probably means with 'screwed': At runtime there is no technical indicator differentiating two instances of A between A<X> and A<Y>. Hence when dealing with A<X> or A<Y>, the JVM just sees twice A (neither <X> nor <Y>). So there cannot be a technical solution other than explicitly providing X and Y as additional parameters to any method that shall be able to understand generics at runtime. Unless an API offers these, you always will end up with plain A... hence you're screwed. ;-)
-Markus
Von: Marek Potociar [mailto:marek.potociar_at_oracle.com]
Gesendet: Montag, 15. August 2016 11:07
An: Users
Betreff: [Jersey] Re: Unmarshalling generic type using Jersey JSON
Hello Hannes,
Generics are generally screwed in Java. I would suggest to wrap your generic content into a wrapper data POJO and work with that POJO. Maybe not ideal, but certainly simplest and least error-prone solution to your problem.
Marek
On 10 Aug 2016, at 15:01, Hannes Hofmann <hannes.hofmann92_at_gmail.com<mailto:hannes.hofmann92_at_gmail.com>> wrote:
Hello together,
I am currently using Jersey JSON to marshal and unmarshal objects and facing a problem when I want to unmarshall an object with a generic type.
Detailed information can be found here:
http://stackoverflow.com/questions/38752940/jersey-json-unmarshalling-generic-typed-class
1. Is it possible to unmarshal an object that contains a generic type?
2. If yes, how..?
Thanks,
Hannes