Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-11718

Setting camel.dataformat.json-jackson.object-mapper throws exception

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.19.2
    • 2.20.0
    • camel-jackson
    • None
    • Unknown

    Description

      I wanted to reuse the Jackson object mapper used by Spring MVC but jackson json configuration via YML is not working an causing an exception

      camel:
        springboot:
          name: ${spring.application.name}
        dataformat:
          json-jackson:
            object-mapper: jacksonObjectMapper
      
      spring:
        jackson:
          property-naming-strategy: com.fasterxml.jackson.databind.PropertyNamingStrategy.SnakeCaseStrategy
          default-property-inclusion: non_null
          serialization:
            WRITE_DATES_AS_TIMESTAMPS: true
      

      Throws the following exception:

      org.apache.camel.spring.boot.CamelSpringBootInitializationException: org.apache.camel.FailedToCreateRouteException: Failed to create route test-public: Route(test-public)[[From[rest:get:/test?routeId=test-public&... because of java.lang.IllegalArgumentException: Could not find a suitable setter for property: objectMapper as there isn't a setter method with same type: java.lang.String nor type conversion possible: No type converter available to convert from type: java.lang.String to the required type: com.fasterxml.jackson.databind.ObjectMapper with value jacksonObjectMapper
      	at org.apache.camel.spring.boot.RoutesCollector.onApplicationEvent(RoutesCollector.java:225)
      	at org.apache.camel.spring.boot.RoutesCollector.onApplicationEvent(RoutesCollector.java:52)
      	at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:167)
      	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
      	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:393)
      	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:347)
      	at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:883)
      	at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:144)
      	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546)
      	at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
      	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
      	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
      	at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
      	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
      	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
      	at au.com.iag.payments.service.OnlinePaymentsApplicationKt.main(OnlinePaymentsApplication.kt:15)
      Caused by: org.apache.camel.FailedToCreateRouteException: Failed to create route test-public: Route(test-public)[[From[rest:get:/test?routeId=test-public&... because of java.lang.IllegalArgumentException: Could not find a suitable setter for property: objectMapper as there isn't a setter method with same type: java.lang.String nor type conversion possible: No type converter available to convert from type: java.lang.String to the required type: com.fasterxml.jackson.databind.ObjectMapper with value jacksonObjectMapper
      	at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:209)
      	at org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:1087)
      	at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:3540)
      	at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:3271)
      	at org.apache.camel.impl.DefaultCamelContext.access$000(DefaultCamelContext.java:202)
      	at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:3089)
      	at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:3085)
      	at org.apache.camel.impl.DefaultCamelContext.doWithDefinedClassLoader(DefaultCamelContext.java:3108)
      	at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:3085)
      	at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
      	at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:3022)
      	at org.apache.camel.spring.boot.RoutesCollector.maybeStart(RoutesCollector.java:242)
      	at org.apache.camel.spring.boot.RoutesCollector.onApplicationEvent(RoutesCollector.java:217)
      	... 15 common frames omitted
      Caused by: org.apache.camel.RuntimeCamelException: java.lang.IllegalArgumentException: Could not find a suitable setter for property: objectMapper as there isn't a setter method with same type: java.lang.String nor type conversion possible: No type converter available to convert from type: java.lang.String to the required type: com.fasterxml.jackson.databind.ObjectMapper with value jacksonObjectMapper
      	at org.apache.camel.component.jackson.springboot.JacksonDataFormatAutoConfiguration$1.newInstance(JacksonDataFormatAutoConfiguration.java:80)
      	at org.apache.camel.impl.DefaultDataFormatResolver.createDataFormat(DefaultDataFormatResolver.java:58)
      	at org.apache.camel.impl.DefaultDataFormatResolver.resolveDataFormat(DefaultDataFormatResolver.java:45)
      	at org.apache.camel.impl.DefaultCamelContext.resolveDataFormat(DefaultCamelContext.java:4240)
      	at org.apache.camel.model.rest.RestBindingDefinition.createRestBindingAdvice(RestBindingDefinition.java:122)
      	at org.apache.camel.impl.DefaultRouteContext.commit(DefaultRouteContext.java:201)
      	at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:1302)
      	at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:204)
      	... 27 common frames omitted
      Caused by: java.lang.IllegalArgumentException: Could not find a suitable setter for property: objectMapper as there isn't a setter method with same type: java.lang.String nor type conversion possible: No type converter available to convert from type: java.lang.String to the required type: com.fasterxml.jackson.databind.ObjectMapper with value jacksonObjectMapper
      	at org.apache.camel.util.IntrospectionSupport.setProperty(IntrospectionSupport.java:614)
      	at org.apache.camel.util.IntrospectionSupport.setProperty(IntrospectionSupport.java:640)
      	at org.apache.camel.util.IntrospectionSupport.setProperties(IntrospectionSupport.java:497)
      	at org.apache.camel.component.jackson.springboot.JacksonDataFormatAutoConfiguration$1.newInstance(JacksonDataFormatAutoConfiguration.java:76)
      	... 34 common frames omitted
      

      I have also tried with

            ...
            object-mapper: "#jacksonObjectMapper"
            ...
      

      to give the property introspection logic a hint that it is a ref, but result is the same.

      Attachments

        1. build.zip
          55 kB
          Roman

        Activity

          People

            davsclaus Claus Ibsen
            strelok1 Roman
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: