[ 
https://issues.apache.org/jira/browse/CAMEL-17956?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17529962#comment-17529962
 ] 

Mikael Andersson Wigander commented on CAMEL-17956:
---------------------------------------------------

The issue is that I can't provide my own registered ObjectMapper to the route 
because deep down in the code when the JsonPathExpression is instantiated an 
engine is created. The engine is built out of JsonPathEngine and it assigns a 
JsonProvider as a JacksonJsonProvider. This provider is defaulting to use its 
own default ObjectMapper.

For _normal_ json parsing the option to provide an ObjectMapper directly the 
DataFormat or thru a registry is present and also for jsonpath()  but not for 
when using jsonpathWriteAsString

> JSONPath option to use global registered ObjectMapper
> -----------------------------------------------------
>
>                 Key: CAMEL-17956
>                 URL: https://issues.apache.org/jira/browse/CAMEL-17956
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-jsonpath
>    Affects Versions: 3.14.2, 3.16.0
>            Reporter: Mikael Andersson Wigander
>            Priority: Minor
>             Fix For: 3.17.0
>
>
> I have discovered that when using JSONPath in a route, the implementation 
> does not use any ObjectMapper registered, it uses it's own.
> {code:java|title=JacksonMappingProvider.class}
> public class JacksonMappingProvider implements MappingProvider {
> private final ObjectMapper objectMapper;
> public JacksonMappingProvider() {
> this(new ObjectMapper());
> }
> public JacksonMappingProvider(ObjectMapper objectMapper) {
> this.objectMapper = objectMapper;
> }
> {code}
> However, when using *.jsonpathWriteAsString()*, this uses global registered 
> ObjectMapper.
> {code:java|title=JacksonJsonAdapter.class}
> @Override
>     public String writeAsString(Object value, Exchange exchange) {
>         ObjectMapper mapper = 
> resolveObjectMapper(exchange.getContext().getRegistry());
>         try {
>             return mapper.writeValueAsString(value);
>         } catch (Throwable e) {
>             // ignore because we are attempting to convert
>         }
>         return null;
>     }
> {code}
> It does not go through the *JsonPathEngine* so it seems it's a completly 
> differrent implementation however still defined within JSONPath language as 
> in this documentation:
> https://camel.apache.org/components/3.14.x/languages/jsonpath-language.html#_split_json_data_into_sub_rows_as_json



--
This message was sent by Atlassian Jira
(v8.20.7#820007)

Reply via email to