ngallagher / simplexml

Simple XML
Apache License 2.0
97 stars 37 forks source link

Fields are not serialized in declaration order on Android #1

Open yogurtearl opened 8 years ago

yogurtearl commented 8 years ago

Fields are not serialized in declaration order on Android and it seems to vary by Android version. e.g. API 21 seems to have a different order compared to API 22.

According to this javadoc, "By default serialization of fields is done in declaration order." http://simple.sourceforge.net/download/stream/doc/javadoc/

Related StackOverflow question: http://stackoverflow.com/questions/7592752/simple-xml-order-of-elements-not-preserved

joaogithub commented 8 years ago

Is there any solution to this?

If not, what is the default serialization criteria?

ngallagher commented 8 years ago

@Order annotation

  From: João Amaro <notifications@github.com>

To: ngallagher/simplexml simplexml@noreply.github.com Sent: Thursday, 11 February 2016, 18:26 Subject: Re: [simplexml] Fields are not serialized in declaration order on Android (#1)

Is there any solution to this?— Reply to this email directly or view it on GitHub.

joaogithub commented 8 years ago

That means that, in order to force a sequence in the serialization, we have to use that annotation. By other words, when not using this @Order annotation, the serialization order is impredictable, is that it? Because changing the field declaration order won't have any effect on the serialization, as it was expected to be.

ngallagher commented 8 years ago

Java in general offers no way to determine declaration order, if you can think of a way to do it then I would be happy to hear it.

  From: João Amaro <notifications@github.com>

To: ngallagher/simplexml simplexml@noreply.github.com Cc: Niall Gallagher gallagher_niall@yahoo.com Sent: Friday, 12 February 2016, 0:56 Subject: Re: [simplexml] Fields are not serialized in declaration order on Android (#1)

That means that, in order to force a sequence in the serialization, we have to use that annotation. By other words, when not using this @Order annotation, the serialization order is impredictable, is that it? Because changing the field declaration order won't have any effect on the serialization, as it was expected to be.— Reply to this email directly or view it on GitHub.