Unmarshalling generic type using Jersey JSON

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Unmarshalling generic type using Jersey JSON

Hannes Hofmann
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Unmarshalling generic type using Jersey JSON

Grzegorz
Hi Hannes,

Yes, it's possible, but it's not Jersey related, but it's JAXB responsibility. You should look in the internet for something like "generic class jaxb serialization".

Ps. Proper answer for you probably is here: http://stackoverflow.com/a/3441569/1037316.

Regards,
Greg


2016-08-10 15:01 GMT+02:00 Hannes Hofmann <[hidden email]>:
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

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Unmarshalling generic type using Jersey JSON

Marek Potociar
In reply to this post by Hannes Hofmann
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 <[hidden email]> 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

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Unmarshalling generic type using Jersey JSON

Markus Karg-2-3

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:[hidden email]]
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 <[hidden email]> 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

 

Loading...