jsr367-experts@jsonb-spec.java.net

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

From: Przemyslaw Bielicki <pbielicki_at_gmail.com>
Date: Mon, 23 Feb 2015 10:04:26 +0100

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
>>
>