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

Mikael Andersson Wigander edited comment on CAMEL-17956 at 4/20/22 2:24 PM:
----------------------------------------------------------------------------

Dug deeper and found this as well:
{code:java|title=JacksonJsonAdapter.class}
public class JacksonJsonAdapter implements JsonPathAdapter {

    private static final String JACKSON_JAXB_MODULE = 
"com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule";

    private final ObjectMapper defaultMapper;
    private CamelContext camelContext;

    public JacksonJsonAdapter() {
        defaultMapper = new ObjectMapper();
    }

    @Override
    public void init(CamelContext camelContext) {
        this.camelContext = camelContext;

        // Attempt to enables JAXB processing so we can easily convert JAXB 
annotated pojos also
        Class<?> clazz = 
camelContext.getClassResolver().resolveClass(JACKSON_JAXB_MODULE);
        if (clazz != null) {
            Object obj = camelContext.getInjector().newInstance(clazz);
            if (obj instanceof Module) {
                Module module = (Module) obj;
                defaultMapper.registerModule(module);
            }
        }
    }
{code}
This one as well defines its own ObjectMapper.

I think the implementation seems much more complex than I thought.


was (Author: hakuseki):
Dug deeper and found this as well:
{code:java|title=JacksonJsonAdapter.class}
public class JacksonJsonAdapter implements JsonPathAdapter {

    private static final String JACKSON_JAXB_MODULE = 
"com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule";

    private final ObjectMapper defaultMapper;
    private CamelContext camelContext;

    public JacksonJsonAdapter() {
        defaultMapper = new ObjectMapper();
    }

    @Override
    public void init(CamelContext camelContext) {
        this.camelContext = camelContext;

        // Attempt to enables JAXB processing so we can easily convert JAXB 
annotated pojos also
        Class<?> clazz = 
camelContext.getClassResolver().resolveClass(JACKSON_JAXB_MODULE);
        if (clazz != null) {
            Object obj = camelContext.getInjector().newInstance(clazz);
            if (obj instanceof Module) {
                Module module = (Module) obj;
                defaultMapper.registerModule(module);
            }
        }
    }
{code}

This one as well defines its own ObjectMapper.

I think the implementation ios much more complex than I thought.


> 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