Hi Federico,

Apologies for my delayed response.

*Here is an example of the route where I am encountering the problem:*
@Component
public class MyRoute {

    public MyRoute() {
        setInput(direct(routeId()));
        setOutput(direct(OUTPUT_ROUTE_ID));
    }

    @Override
    public void configure() throws Exception {
        super.configure();

        from(getInput())
                .routeId(routeId())
                .unmarshal().json(MyPojo.class)
                // processing data
                .to(getOutput())
                .end();
    }
}
*Executable version: * @Component
public class MyRoute {

    private final ObjectMapper objectMapper;

    public MyRoute(ObjectMapper objectMapper) {
        this.objectMapper = objectMapper;

        setInput(direct(routeId()));
        setOutput(direct(OUTPUT_ROUTE_ID));
    }

    @Override
    public void configure() throws Exception {
        super.configure();
        JacksonDataFormat jacksonDataFormat = new
JacksonDataFormat(MyPojo.class);
        jacksonDataFormat.setObjectMapper(objectMapper);

        from(getInput())
                .routeId(routeId())
                .unmarshal(jacksonDataFormat)
                // processing data
                .to(getOutput())
                .end();
    }
}
By the way, I am currently using Spring Boot 2.5.0.

Le jeu. 16 mai 2024 à 10:30, Federico Mariani <
federico.mariani.1...@gmail.com> a écrit :

> Hi,
>
> Can you provide a reproducer? one thing that pops up from the environment
> description is the Spring Boot version, in particular, with Camel 4.5.0,
> you should use Spring Boot 3.2.5, can you update the spring boot version
> and try again?
>
> Il giorno gio 16 mag 2024 alle ore 10:57 Ghassen Kahri <
> ghassen.ka...@codeonce.fr> ha scritto:
>
> > Hi folks,
> >
> > I am encountering an issue while migrating from Camel 4.0.3 to Camel
> 4.5.0.
> > Below is my Jackson configuration class:
> >
> > @Configuration
> > public class JacksonConfiguration {
> >
> >     @Primary
> >     @Bean("json-mapper")
> >     public ObjectMapper objectMapper() { return configure(new
> > ObjectMapper()); }
> >
> >     @Bean
> >     @Primary
> >     public JacksonDataFormatConfiguration
> jacksonDataFormatConfiguration()
> > {
> >         JacksonDataFormatConfiguration config = new
> > JacksonDataFormatConfiguration();
> >         config.setObjectMapper("json-mapper");
> >         return config;
> >     }
> >
> >     private ObjectMapper configure(ObjectMapper mapper) {
> >         return mapper
> >                 .setSerializationInclusion(NON_NULL)
> >
> > .setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE)
> >                 .enable(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS)
> >                 .disable(SerializationFeature.FAIL_ON_EMPTY_BEANS)
> >                 .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
> >
> > .disable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE)
> >
>  .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
> >                 .registerModule(new JavaTimeModule())
> >                 .registerModule(new Jdk8Module())
> >                 .registerModule(new GuavaModule())
> >                 .findAndRegisterModules();
> >     }
> > }
> >
> > In the new version, I get an error indicating that Camel cannot
> deserialize
> > Optional<Integer> when using .unmarshal().json(JsonLibrary.Jackson,
> > XXX.class). Upon debugging, I discovered that Camel requires the
> Jdk8Module
> > for this operation. It seems that my Jackson configuration is not being
> > scanned in the application.
> >
> > Using the following syntax in my route resolves the error:
> >
> > JacksonDataFormat jacksonDataFormat = new JacksonDataFormat(XXX.class);
> > jacksonDataFormat.setObjectMapper(objectMapper);
> > .
> > .
> > .
> > .unmarshal(jacksonDataFormat);
> >
> > Do I need to explicitly import my configuration each time I need to
> > deserialize a POJO?
> >
> > Old Environment:
> >
> >    - Camel: 4.0.3
> >    - Spring Boot: 3.1.6
> >    - Java: 17
> >
> > New Environment:
> >
> >    - Camel: 4.5.0
> >    - Spring Boot: 3.1.6
> >    - Java: 17
> >
>

Reply via email to