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

JSONPath option to use global registered ObjectMapper

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 3.14.2, 3.16.0
    • 3.17.0
    • camel-jsonpath
    • None
    • Advanced

    Description

      I have discovered that when using JSONPath in a route, the implementation does not use any ObjectMapper registered, it uses it's own.

      JacksonMappingProvider.class
      public class JacksonMappingProvider implements MappingProvider {
      
      private final ObjectMapper objectMapper;
      
      public JacksonMappingProvider() {
      this(new ObjectMapper());
      }
      
      public JacksonMappingProvider(ObjectMapper objectMapper) {
      this.objectMapper = objectMapper;
      }
      

      However, when using .jsonpathWriteAsString(), this uses global registered ObjectMapper.

      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;
          }
      

      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

      Attachments

        1. JsonPathCustomMapperTest.java
          4 kB
          Karen Lease

        Issue Links

          Activity

            People

              klease78 Karen Lease
              hakuseki Mikael Andersson Wigander
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: