This is an automated email from the ASF dual-hosted git repository.
gnodet pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cxf.git
The following commit(s) were added to refs/heads/main by this push:
new a007b8e89a Use LinkedHashSet for deterministic JAXB property ordering
(#2945)
a007b8e89a is described below
commit a007b8e89a6253531798b3225d7827a167940290
Author: Guillaume Nodet <[email protected]>
AuthorDate: Wed Mar 11 18:09:40 2026 +0100
Use LinkedHashSet for deterministic JAXB property ordering (#2945)
Utils.getFields() and Utils.getGetters() use HashSet to collect bean
properties from reflection, which produces non-deterministic iteration
order. This causes serialized XML element order to vary between runs
when @XmlType(propOrder) is not specified.
Switch to LinkedHashSet to preserve insertion order (matching
Class.getDeclaredFields/Methods order), ensuring deterministic
serialization without requiring explicit propOrder on every bean.
Co-authored-by: Claude Opus 4.6 <[email protected]>
---
rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/Utils.java | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/Utils.java
b/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/Utils.java
index 96880f38ea..56942952f6 100644
--- a/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/Utils.java
+++ b/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/Utils.java
@@ -27,7 +27,7 @@ import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.Collection;
-import java.util.HashSet;
+import java.util.LinkedHashSet;
import java.util.Set;
import jakarta.xml.bind.annotation.XmlAccessType;
@@ -58,7 +58,7 @@ final class Utils {
}
private static Collection<Field> getFieldsInternal(Class<?> cls,
XmlAccessType accessType) {
- Set<Field> fields = new HashSet<>();
+ Set<Field> fields = new LinkedHashSet<>();
Class<?> superClass = cls.getSuperclass();
if (superClass != null && !superClass.equals(Object.class) &&
!superClass.equals(Throwable.class)) {
// process super class until java.lang.Object or
java.lang.Throwable is not reached
@@ -79,7 +79,7 @@ final class Utils {
private static Collection<Method> getMethodsInternal(Class<?> cls,
XmlAccessType accessType,
boolean acceptSetters) {
- Set<Method> methods = new HashSet<>();
+ Set<Method> methods = new LinkedHashSet<>();
Class<?> superClass = cls.getSuperclass();
if (superClass != null && !superClass.equals(Object.class) &&
!superClass.equals(Throwable.class)) {
// process super class until java.lang.Object or
java.lang.Throwable is not reached