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

José Bustamante edited comment on CAMEL-18345 at 8/4/22 9:54 AM:
-----------------------------------------------------------------

Thanks for your reply. I  just tested with latest camel (3.18.0) and the latest 
jackson-dataformat-xml (2.13.3) and I'm having the same issue. I've created a 
basic project with the latest camel 3 and I've implemented a small unit test.

If I use this 
{quote}from("direct:start").unmarshal().jacksonXml(Header.class, true)
{quote}
I'm getting the empty object transformed (the difference in blue)

!image-2022-08-04-11-41-09-007.png|width=787,height=72!

But if I create a custom XMLMapper with the property manually enabled 
{quote}.unmarshal(createCustomJacksonXMLDataformat(Header.class))
{quote}
{{The property manually enabled (in bold)}}
{quote}private JacksonXMLDataFormat createCustomJacksonXMLDataformat(Class<?> 
type)
Unknown macro: \{      JacksonXMLDataFormat dataFormat = new 
JacksonXMLDataFormat();      XmlMapper xmlMapper = new XmlMapper();      
*xmlMapper.configure(FromXmlParser.Feature.EMPTY_ELEMENT_AS_NULL, true);*      
xmlMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);  
    dataFormat.setXmlMapper(xmlMapper);      dataFormat.setUnmarshalType(type); 
     return dataFormat; }{quote}
It works.

!image-2022-08-04-11-48-11-568.png|width=967,height=116!

What we need is to use jacksonXml with some configuration in order to enable 
this feature in our XML DSL routes, instead of creating the custom 
JacksonXMLDataformat with XMLMapper. In our project we use XML DLS so 
implementing this is more complex than doing it with Java DSL.

Thanks in  advnace for your help


was (Author: wayqui):
Thanks for your reply. I  just tested with latest camel (3.18.0) and the latest 
jackson-dataformat-xml (2.13.3) and I'm having the same issue. I've created a 
basic project with the latest camel 3 and I've implemented a small unit test.

If I use this 
{quote}from("direct:start").unmarshal().jacksonXml(Header.class, true)
{quote}
I'm getting the empty object transformed (the difference in blue)

!image-2022-08-04-11-41-09-007.png!

But if I create a custom XMLMapper with the property manually enabled 
{quote}.unmarshal(createCustomJacksonXMLDataformat(Header.class)){quote}
{{The property manually enabled (in bold)}}
{quote}private JacksonXMLDataFormat createCustomJacksonXMLDataformat(Class<?> 
type) {
     JacksonXMLDataFormat dataFormat = new JacksonXMLDataFormat();
     XmlMapper xmlMapper = new XmlMapper();
     *xmlMapper.configure(FromXmlParser.Feature.EMPTY_ELEMENT_AS_NULL, true);*
     xmlMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, 
false);
     dataFormat.setXmlMapper(xmlMapper);
     dataFormat.setUnmarshalType(type);
     return dataFormat;
}
{quote}
It works.

!image-2022-08-04-11-48-11-568.png|width=967,height=116!

What we need is to use jacksonXml with some configuration in order to enable 
this feature in our XML DSL routes, instead of creating the custom 
JacksonXMLDataformat with XMLMapper. In our project we use XML DLS so 
implementing this is more complex than doing it with Java DSL.

Thanks in  advnace for your help

> EMPTY_ELEMENT_AS_NULL disabled by default in jackson-dataformat-xml
> -------------------------------------------------------------------
>
>                 Key: CAMEL-18345
>                 URL: https://issues.apache.org/jira/browse/CAMEL-18345
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-jacksonxml
>    Affects Versions: 3.3.0
>            Reporter: José Bustamante
>            Priority: Major
>         Attachments: image-2022-08-04-11-36-25-666.png, 
> image-2022-08-04-11-41-09-007.png, image-2022-08-04-11-48-11-568.png
>
>
> Jackson 2.12.x changed the default for the 'EMPTY_ELEMENT_AS_NULL' feature 
> from true to false (see 
> [here|[https://github.com/FasterXML/jackson-dataformat-xml/issues/411]]) and 
> we can enable back this property using XMLMapper:
> {quote}xmlMapper.configure(FromXmlParser.Feature.EMPTY_ELEMENT_AS_NULL, true);
> {quote}
> However, there's no way to enable this behaviour in jaxonxml inside camel 
> routes. In the 
> [documentation|[https://camel.apache.org/components/3.14.x/dataformats/jacksonxml-dataformat.html#_enabling_or_disable_features_using_jackson],]
>  It's specified that we can enable or disable certain types of properties 
> that are inside SerializationFeature, DeserializationFeature and 
> MapperFeature but there's no way to enable EMPTY_ELEMENT_AS_NULL since is in 
> another enum (FromXmlParser). We've tried enabling the feature 
> ACCEPT_EMPTY_STRING_AS_NULL_OBJECT but that doesn't work either.
> We've managed to implement a workaround by using <bean> instead of 
> <jacksonxml> in our camel routes (we use Camel XML DSL), but that's not 
> efficient as we would have to replace all <jacksonxml> references. So we need 
> to have the possibility to enable back EMPTY_ELEMENT_AS_NULL from 
> <jacksonxml> in camel XML DSL.
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to