camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Zoran Regvart <zo...@regvart.com>
Subject Re: Gson Json unmarshal List
Date Thu, 02 Nov 2017 12:13:05 GMT
Hi Jerry,
I think you need to use the type token pattern, that is the
TypeToken[1] subclass, something like:

    .unmarshal().json(JsonLibrary.Gson, new
TypeToken<List<MyPojo>>(){}.getClass())

zoran

[1] https://google.github.io/gson/apidocs/com/google/gson/reflect/TypeToken.html

On Wed, Nov 1, 2017 at 10:47 PM, Jerry Smith <jerry.smith.ii@gmail.com> wrote:
> Using the Camel 2.19.3 Java DSL how do I go about unmarshalling a list of
> pojos?
>
> Currently I've tried:
>
> .unmarshal().json(JsonLibrary.Gson, new ArrayList<MyPojo>().getClass())
>
> but the generic gets erased so Gson has no idea what it's a list of, so
> then I tried this for grins:
>
> .unmarshal().json(JsonLibrary.Gson, MyPojo.class)
>
> hoping the library would be pick up it was an array of this type, but it
> doesn't.



-- 
Zoran Regvart

Mime
View raw message