Camel v3.14 does not register global deserializer to unmarshall json

39 views Asked by At

Using Apache camel v3.14.x with idk 1.8 and I am not using springboot but war deploys to EAP. I have all the desired camel and spring dependencies including com.fasterxml.jackson.datatype:jackson-datatype-jsr310

I have this configuration working fine with camel v2.x but when I upgrade camel to v3.14.x I start to get following error. ..

Error During Camel route Processing - Java 8 date/time type 'java.time.LocalDate' not supported by default add module "com.fasterxml.jackson.datatype:jackson-datatype-jsr310'

I can see "jsr310" registered in modules of Objectmapper registered modules set if I debug.

if I @autowire objectMapper in camel route and manually objectmapper.readValue(input, Model.class) it seems to work fine.

Seems like camel is not picking up object mapper already created but creating its own, any help is apperciated.

@Configuration
public class CamelConfiguration extends CamelConfiguration{
 
  @override
  public void setupCamelContext(CamelContext context){
  context.setAllowOriginalMessage(false);
  context.setLogMask(true);
  context.setAutoStartup(false);
    
  }
 
  @Bean
  public CamelRoutesStarter routesStarter(CamelContext context){
   return new CamelRoutesStarter(context)
  }

}

@Configuration
public class serviceConfig {
@primary
@Bean
public ObjectMapper objectMapper(){
  Jackson2Obj ectMapperBuilder.json().serializationIncludsion(non_empty)
  .featureToDisable(WRITE_DATES_AS_TIMESTAMPS).deserializerByType(LocalDate.class, new CustomDateDeserialier())
 }
}

@override
public class CustomDateDeserialier extends StdScalarDeserilaizer<LocalDate>{

  public LocalDate deserialize(JsonParser parser, DeseralizationContext context){
    ..
  }
}

// my camel route
@Component
public MyRoute{

from("my http request")
.unmarshal().json(Jackson, Model.class)
.to("bla bla");

}

// my model
public class Model {

public LocalDate date;

}

instead if I try following it works.

@Component
    public MyModifiedRoute{
    
    @Autowire
    private ObjectMapper mapper;
    private JacksonDataFormat dataFmt;

    @PostConstruct()
    public void post(){
      dataFmt = new JacksonDataFormat(mapper, Model.class)
     }

    from("my http request")
    .unmarshal(dataFmt) //.json(Jackson, Model.class)
    .to("bla bla");
    
    }
}
0

There are 0 answers