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

Karen Lease commented on CAMEL-17956:
-------------------------------------

The attached test case [^JsonPathCustomMapperTest.java] shows the use of 
registering a custom ObjectMapper with a serializer for Double values which is 
used by jsonpathWriteAsString(). When run with the json content above, it logs 
this: 
\{"adjustedRate":1.230000,"collateralQuantityOrNominalAmount":987.654321,"fixedRate":-0.620000,"floatingRate":4.560000,"principalAmountOnMaturityDate":121002700.000000,"principalAmountOnValueDate":-91000000.000000,"spread":4.560000}

I agree it is not used when reading the json, but does this solution address 
your problem?

> 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
>
>         Attachments: JsonPathCustomMapperTest.java
>
>
> 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