I have 2 different camel routes.
1)
from(...).routeId(...)
.unmarshal().json(SomeClass.class)
....;
And 2)
from(...).routeId(...)
.unmarshal(new ListJacksonDataFormat(SomeOtherClass.class))
....;
Both SomeClass
and SomeOtherClass
have field named timestamp whose type is java.time.ZonedDateTime
.
In first route I pass single object and it unmarshals without errors. In 2nd route I pass a list of objects and it does not work:
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Java 8 date/time type
java.time.ZonedDateTime
not supported by default: add Module "com.fasterxml.jackson.datatype:jackson-datatype-jsr310" to enable handling
Questions:
- Do I correctly understand that if I want to unmarshal list I need to use
.unmarshal(new ListJacksonDataFormat(...))
instead of.unmarshal().json(...)
? - Do I really need to add Module
com.fasterxml.jackson.datatype:jackson-datatype-jsr310
? Otherwise I would have added it without even asking here but since my first route can manage ZonedDateTime just fine I wanted to be sure that I really have to add a new module or if there are any other means of dealing with it? It's strange that first route can unmarshal ZonedDateTime fine and 2nd can't.
After .unmarshal(...)
I plan to call .bean(..., "method")
where method takes List as argument. Not sure if this extra info is needed but added it just in case.
CodePudding user response:
Your first option uses the xstream library to unmarshal json. See the javadoc for the json method.
Your second option is using jackson.
Apparently, you have the correct dependencies to allow xstream to unmarshal the java.time.ZonedDateTime
object, but you do not have the correct dependencies to do so with jackson.
You will probably want to do some research and pick which library you would like to use for your json parsing and stick to one across your project