users@jsonb-spec.java.net

[jsonb-spec users] [jsr367-experts] Re: Re: Re: Re: [2-DefaultMapping] Proposal

From: Romain Manni-Bucau <rmannibucau_at_gmail.com>
Date: Mon, 23 Feb 2015 10:08:42 +0100

Hi

FYI EE has TypeLiteral for the exact same purpose
http://docs.oracle.com/javaee/6/api/javax/enterprise/util/TypeLiteral.html.

I know we'll not bring cdi spec for it but for the naming it would be
nice to maybe be closer (Literal is sued for Type but Annotation as
well)



Romain Manni-Bucau
@rmannibucau
http://www.tomitribe.com
http://rmannibucau.wordpress.com
https://github.com/rmannibucau


2015-02-23 10:04 GMT+01:00 Przemyslaw Bielicki <pbielicki_at_gmail.com>:
> Hi Eugen,
>
> thanks a lot for complete example! I think we should go TypeToken way.
>
> Przemyslaw
>
> On Sun, Feb 22, 2015 at 6:56 PM, Eugen Cepoi <cepoi.eugen_at_gmail.com> wrote:
>>
>> fromJson(json, MyPojo.class) returns an instance of MyPojo, no need to
>> cast.
>> How to deser to a list of MyPojo (or any other generic type)?
>>
>> List<MyPojo> fromJson(json, new TypeToken<List<MyPojo>>() {})
>>
>> An example of impl
>> https://github.com/owlike/genson/blob/master/genson/src/main/java/com/owlike/genson/GenericType.java
>>
>> You can also have a look at guavas Typetoken impl which is more
>> sophisticated.
>>
>> This should avoid all kind of casts when the user knows what the actual
>> type should be.
>>
>> Le 22 févr. 2015 00:17, "Przemyslaw Bielicki" <pbielicki_at_gmail.com> a
>> écrit :
>>
>>> Hi,
>>>
>>> Yes these methods are a bit redundant, I agree.
>>> Do you have better idea how to avoid casts and
>>> @SuppressWarnings("unchecked") annotation? Can we achieve this using
>>> combination of Class and TypeToken? Because forcing end users to do so
>>> (casts and suppress) stinks in a modern API.
>>>
>>> I have one more comment regarding POJO but don't have time to express
>>> myself ;)
>>>
>>> Stay tuned,
>>> Przemyslaw
>
>