Junior5413
Junior5413

Reputation: 83

How to unmarshal json body to list of myclass in camel

I'd like to know how to unmarshal JSON string body to List of MyClass. The following sample doesn't work well.

from("direct:testroute")
.log("Received body ${body}")
.unmarshal().json(JsonLibrary.Jackson, List.class)

And I'd like to have something like (obviously doesn't work too)

from("direct:testroute")
.log("Received body ${body}")
.unmarshal().json(JsonLibrary.Jackson, List<MyClass>.class)

Upvotes: 6

Views: 9959

Answers (2)

Josef Vesel&#253;
Josef Vesel&#253;

Reputation: 112

Cannot you simply unmarshall as an array?

.unmarshal().json(JsonLibrary.Jackson, MyClass[].class)

I know it's not answer on how to unmarshall as a List but maybe someone can find it useful.

Upvotes: 0

Adrian
Adrian

Reputation: 3134

Create

JacksonDataFormat format = new ListJacksonDataFormat(MyClass.class);

and then:

//...
.unmarshal(format)
//...

source

Upvotes: 15

Related Questions