Unmarshal Map to POJO with Jackson data format

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Unmarshal Map to POJO with Jackson data format

Jeremy Ross
Howdy,

Is it possible to unmarshal from a Map to POJO with the Jackson data
format? When I pass it a map, I get:

org.apache.camel.InvalidPayloadException: No body available of type:
java.io.InputStream but has value...

ObjectMapper#convertValue supports this, but I'm not sure how to play nice
with the data format. Any tips are appreciated!

Jeremy
Reply | Threaded
Open this post in threaded view
|

Re: Unmarshal Map to POJO with Jackson data format

Sneharghya Pathak
Hi Jeremy,

The way I fixed it was to first convert it to json and then to a pojo, like
so:

.marshal().json(JsonLibrary.Jackson) .unmarshal().json(JsonLibrary.Jackson,
MyClass.class)

Regards,
Sneharghya


On Mon, 3 Aug 2020, 10:25 pm Jeremy Ross, <[hidden email]> wrote:

> Howdy,
>
> Is it possible to unmarshal from a Map to POJO with the Jackson data
> format? When I pass it a map, I get:
>
> org.apache.camel.InvalidPayloadException: No body available of type:
> java.io.InputStream but has value...
>
> ObjectMapper#convertValue supports this, but I'm not sure how to play nice
> with the data format. Any tips are appreciated!
>
> Jeremy
>
Reply | Threaded
Open this post in threaded view
|

Re: Unmarshal Map to POJO with Jackson data format

Jeremy Ross
Hey Sneharghya,

Thanks, that is my workaround. Just hoping for something a little more
efficient.

On Mon, Aug 3, 2020 at 2:36 PM Sneharghya Pathak <[hidden email]>
wrote:

> Hi Jeremy,
>
> The way I fixed it was to first convert it to json and then to a pojo, like
> so:
>
> .marshal().json(JsonLibrary.Jackson) .unmarshal().json(JsonLibrary.Jackson,
> MyClass.class)
>
> Regards,
> Sneharghya
>
>
> On Mon, 3 Aug 2020, 10:25 pm Jeremy Ross, <[hidden email]> wrote:
>
> > Howdy,
> >
> > Is it possible to unmarshal from a Map to POJO with the Jackson data
> > format? When I pass it a map, I get:
> >
> > org.apache.camel.InvalidPayloadException: No body available of type:
> > java.io.InputStream but has value...
> >
> > ObjectMapper#convertValue supports this, but I'm not sure how to play
> nice
> > with the data format. Any tips are appreciated!
> >
> > Jeremy
> >
>
Reply | Threaded
Open this post in threaded view
|

Re: Unmarshal Map to POJO with Jackson data format

Mark Nuttall
you could add an inline processor and specifically call the ObjectMapper
method you need. Or some variant of that. While it is not an OOTB camel
component, it is one less conversion.

On Mon, Aug 3, 2020 at 9:49 PM Jeremy Ross <[hidden email]> wrote:

> Hey Sneharghya,
>
> Thanks, that is my workaround. Just hoping for something a little more
> efficient.
>
> On Mon, Aug 3, 2020 at 2:36 PM Sneharghya Pathak <[hidden email]>
> wrote:
>
> > Hi Jeremy,
> >
> > The way I fixed it was to first convert it to json and then to a pojo,
> like
> > so:
> >
> > .marshal().json(JsonLibrary.Jackson)
> .unmarshal().json(JsonLibrary.Jackson,
> > MyClass.class)
> >
> > Regards,
> > Sneharghya
> >
> >
> > On Mon, 3 Aug 2020, 10:25 pm Jeremy Ross, <[hidden email]>
> wrote:
> >
> > > Howdy,
> > >
> > > Is it possible to unmarshal from a Map to POJO with the Jackson data
> > > format? When I pass it a map, I get:
> > >
> > > org.apache.camel.InvalidPayloadException: No body available of type:
> > > java.io.InputStream but has value...
> > >
> > > ObjectMapper#convertValue supports this, but I'm not sure how to play
> > nice
> > > with the data format. Any tips are appreciated!
> > >
> > > Jeremy
> > >
> >
>