1

I have the following config

<dataFormats>
        <json id="orderModel" library="Jackson" objectMapper="com.camel.CustomObjectMapper"
              unmarshalTypeName="com.orders.OrderModel"/>
        <json id="salesOrder" library="Jackson" objectMapper="com.camel.CustomObjectMapper"
              unmarshalTypeName="com.camel.model.salesorder.SalesOrder"/>
</dataFormats>

<route id="orderTranslateToSalesOrder">
        <from ref="orderPlaced"/>
        <unmarshal ref="orderModel" />
        <process ref="customerProcessor" />
        <process ref="salesOrderConverter"/>
        <marshal ref="salesOrder"/>
        <inOnly ref="orderCreate" />
        <process ref="history"/>
</route>

I read from orderPlaced which is a rabbit queue, then unmarshal the object to an OrderModel, then perform two process, where the second process changes the body object type from OrderModel to SalesOrder, but when marshaling the message I get an error

com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "SalesOrder" (class com.orders.OrderModel), not marked as ignorable at [Source: java.io.ByteArrayInputStream@4eac8add; line: 1, column: 16] (through reference chain: com.orders.OrderModel["SalesOrder"]) at com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:62) at com.fasterxml.jackson.databind.DeserializationContext.handleUnknownProperty(DeserializationContext.java:834) at com.fasterxml.jackson.databind.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:1093) at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownProperty(BeanDeserializerBase.java:1489) at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownVanilla(BeanDeserializerBase.java:1467) at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:282) at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:140) at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3814) at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2924) at org.apache.camel.component.jackson.JacksonDataFormat.unmarshal(JacksonDataFormat.java:185) at org.apache.camel.processor.UnmarshalProcessor.process(UnmarshalProcessor.java:69) at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:76) at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:548) at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201) at org.apache.camel.processor.Pipeline.process(Pipeline.java:138) at org.apache.camel.processor.Pipeline.process(Pipeline.java:101) at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201) at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:97) at org.apache.camel.component.rabbitmq.RabbitConsumer.doHandleDelivery(RabbitConsumer.java:99) at org.apache.camel.component.rabbitmq.RabbitConsumer.handleDelivery(RabbitConsumer.java:74) at com.rabbitmq.client.impl.ConsumerDispatcher$5.run(ConsumerDispatcher.java:149) at com.rabbitmq.client.impl.ConsumerWorkService$WorkPoolRunnable.run(ConsumerWorkService.java:100) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:748) Suppressed: com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "SalesOrder" (class com.orders.OrderModel), not marked as ignorable at [Source: java.io.ByteArrayInputStream@4a931757; line: 1, column: 16] (through reference chain: com.orders.OrderModel["SalesOrder"]) ... 25 more

Although I am specifying for the marshal to use the salesOrder data format, at the end when doing things for some reason it is using the orderModel data format, but I can not determine why.

This is what the SalesOrderConverter does at the end

exchange.getOut().setHeaders(exchange.getIn().getHeaders());
exchange.getOut().setBody(salesOrder, SalesOrder.class);
Ale
  • 102
  • 1
  • 7

2 Answers2

1

Unrecognized field "SalesOrder" because you haven't mapped this field in your pojo. if you don't want to map then also you should include in your pojo and have annotation @JsonIgnore

Minal
  • 11
  • 1
0

If your ExchangePattern is set to InOnly (which it looks like it is) the Out-part of your exchange will be discarded.

Change

exchange.getOut().setHeaders(exchange.getIn().getHeaders());
exchange.getOut().setBody(salesOrder, SalesOrder.class);

To this:

exchange.getIn().setBody(salesOrder, SalesOrder.class);

That way you won't have to copy your headers from the In-part either as they will already be there.

You can read more about how and when to use getIn/getOut here.

Erik Karlstrand
  • 1,479
  • 9
  • 22
  • Thanks for the info, I tried with `exchange.getIn().setBody(salesOrder, SalesOrder.class);` but still have the same issue – Ale Feb 28 '18 at 16:59