On Fri, Mar 10, 2017 at 6:09 AM, Diego Oliveira <[email protected]> wrote:
> Tatu,
>
>     Thanks for your time appreciating the subject.
>
>     I understand that for the json representation the root element name is
> irrelevant, but not so for an xml schema. I also think that the XmlObject
> must retain the root element name when reading an ObjectNode entry. I'm not

The is no such thing as XmlObject in Jackson so I am not sure what you
are referring to.

> that fluent in the jackson code base, I'll try to take a look to find the
> place to make the change and propose a patch, if you have any clue to drive
> me to the probable place, please, fell free to do so.

As per README of the XML repo, Tree Model is not officially supported
and while I am not opposed to changes that can help with
interoperability there is no intent to make it work like a real XML
tree model like DOM. It is what it is.

Jackson XML module is meant to be used for binding XML to/from POJOs,
and so although it does implement streaming API to work with
data-binding, and by virtue of doing this also does allow use of Tree
Model, direct use of Streaming and Tree Models on XML is not a
supported use case.

-+ Tatu +-

>
> --
> D.
>
> Em segunda-feira, 6 de março de 2017 21:52:36 UTC-3, Tatu Saloranta
> escreveu:
>>
>> The problem with your code is that you are for some reason assuming
>> that `user` would be dropped for some reason: it is not. JSON
>> structure that would be equivalent is rather:
>>
>> { "user" : {
>>      "name" : "Joe",
>>      "age" : 28
>>   }
>> }
>>
>> So basically there is no 'age' property in main level object: there is
>> just 'user'. This is by design; while there is no guarantee Tree model
>> api works (it is not officially supported by XML backend), it will try
>> to represent XML content as closely as possible.
>> The only way to do that is to retain root element name as well.
>>
>> -+ Tatu +-
>>
>>
>> On Mon, Mar 6, 2017 at 1:34 PM, Diego Oliveira <[email protected]>
>> wrote:
>> > Hello all,
>> >
>> >     I'm using the Jackson json library to work with some Json/Xml
>> > content,
>> > the content type is dynamic. My feature needs to open the payload,
>> > remove
>> > some data and generate a new version. The problem I'm getting is the way
>> > Jackson is handling the root element name for xml content. Follows one
>> > example that works and one that don't.
>> >
>> > Prints different, but I wanted it to be equal
>> >
>> >             ObjectMapper xmlMapper = new XmlMapper();
>> >
>> >         String original = "<user><name>jhon</name><age>28</age></user>";
>> >         String expected = "<user><name>jhon</name></user>";
>> >
>> >         ObjectNode obj = xmlMapper.readValue(original,
>> > ObjectNode.class);
>> >         obj.remove("age");
>> >
>> >         String serialized = xmlMapper.writeValueAsString(obj);
>> >
>> >         if (expected.equals(serialized)) {
>> >             System.out.println("Equals");
>> >         } else {
>> >             System.out.println("Different");
>> >         }
>> >
>> > Print equals as expected
>> >
>> >         ObjectMapper jsonMapper = new ObjectMapper();
>> >
>> >         String original = "{\"name\":\"Joe\",\"age\":28}";
>> >         String expected = "{\"name\":\"Joe\"}";
>> >
>> >         ObjectNode obj = jsonMapper.readValue(original,
>> > ObjectNode.class);
>> >         obj.remove("age");
>> >         String serialized = jsonMapper.writeValueAsString(obj);
>> >
>> >         if (expected.equals(serialized)) {
>> >             System.out.println("Equals");
>> >         } else {
>> >             System.out.println("Different");
>> >         }
>> >
>> >     The gist contains the full example code
>> > https://gist.github.com/diegooliveira/34252ae174cfee4e52628ecfc962aaf1.
>> > Are
>> > there any way that this code might work properly?
>> >
>> > Thanks in advance,
>> > D.
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "jackson-user" group.
>> > To unsubscribe from this group and stop receiving emails from it, send
>> > an
>> > email to [email protected].
>> > To post to this group, send email to [email protected].
>> > For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "jackson-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to