JAXB 编译器和属性顺序
我想控制 JAXB 编译器生成的 .java 文件中的属性顺序.
I would like to control the attribute order in .java files generated by the JAXB compiler.
我知道属性顺序对于 xml 验证并不重要.该顺序对于回归测试环境中编组 xml 的文本比较很重要.文件中属性的顺序直接影响编组的 xml 标签中的属性顺序.
I'm aware that attribute order is not important for xml validation. The order is important for textual comparison of marshalled xml in a regression test environment. The order of attributes in a file directly affects the order of the attributes in marshalled xml tags.
每次运行 JAXB 编译器时,属性组都会以不同的顺序出现,即使架构没有更改.编译器上没有明显的选项来防止这种行为.
Every time the JAXB compiler is run attribute groups appear in a different order, even with no changes to the schema. There is no apparent option available on the compiler to prevent this behavior.
我想避免运行编译后脚本来按字母顺序对生成的 .java 文件中的属性重新排序,因为这会破坏属性组,但我不确定是否还有其他选择.
I would like to avoid running a post-compilation script to alphabetically reorder attributes in the generated .java files since this breaks up the attribute groups, but I'm not sure there is another option.
非常感谢任何建议.
谢谢,戴夫
显然,在 JAXB 2.0 中你可以使用注解 @XmlAccessorOrder 或 @XmlType(propOrder=)
Apparently, in JAXB 2.0 you can use the annotation @XmlAccessorOrder or @XmlType(propOrder=)