79484364

Date: 2025-03-04 17:03:25
Score: 0.5
Natty:
Report link

I was unable to set the guidewire ObjectMapper via configuration. The "good enough" solution I arrived at is thus: in the route class extending GwRouteBuilder

@Inject
private ObjectMapper jacksonObjectMapper;  //ObjectMapper from Spring

In the configure() method:

JacksonDataFormat jacksonDataFormat = new JacksonDataFormat();
jacksonDataFormat.setObjectMapper(jacksonObjectMapper);
jacksonDataFormat.setCamelContext(getCamelContext());

In the route definitions when serializing the body, instead of using:

.marshal().json()            //marshal body object to json

use:

.marshal(jacksonDataFormat)  //transform body into json string using custom dataformat

This has the added benefit of having the injected object mapper available for deserializing, i.e.

String s=exchange.getMessage().getBody(String.class);
Whatever parsed=jacksonObjectMapper.readValue(s, Whatever.class);
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: David VanderMolen