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
>