pradeepsjsu / beanio

Automatically exported from code.google.com/p/beanio
Apache License 2.0
0 stars 0 forks source link

'at' order ignored for XML attributes (alphabetical order instead?) #120

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
It seems that the order of appearance of XML attributes does not match the 
order defined by the 'at' attribute of the @Field annotation.

Here are excerpts of code to illustrate this problem:

[--- Record bean with BeanIO annotations ---]

@Record(minOccurs=1, maxOccurs=1)
@lombok.Data
public class AttrOrderTestBean {
    @Field(at=1, xmlType=XmlType.ATTRIBUTE)
    private String foo;

    @Field(at=2, xmlType=XmlType.ATTRIBUTE)
    private String bar;

    @Field(at=3, xmlType=XmlType.ATTRIBUTE)
    private String thing;
}

[--- Stream definition in BeanIO XML configuration file ---]

<stream name="test-stream" format="xml" xmlType="none">
    <parser>
        <property name="suppressHeader" value="true" />
        <property name="encoding" value="" />
    </parser>
    <record name="attr-order-test" class="test.AttrOrderTestBean" />
</stream>

[--- Bean creation ---]

AttrOrderTestBean bean = new AttrOrderTestBean();
bean.setFoo("1");
bean.setBar("2");
bean.setThing("3");

[--- Output of a BeanWriter.write() with XML attributes in wrong order ---]

<importFile bar="2" foo="1" thing="3"></importFile>

[--- Remark ---]

On this example, it looks like the order followed by the attribute is the 
alphabetical order.

Original issue reported on code.google.com by maxime.b...@gmail.com on 22 Aug 2014 at 3:16

GoogleCodeExporter commented 8 years ago
BeanIO relies on the underlying Java DOM implementation for modeling XML.  This 
won't be changed for the foreseeable future, but it might be possible to swap 
the DOM implementation for one that honors the order in which attributes are 
added (if such a library exists).

Original comment by kevin.s...@gmail.com on 26 Aug 2014 at 3:03