Skip to content

Commit 35dbcf0

Browse files
committed
Fixed #91
1 parent 6459114 commit 35dbcf0

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

release-notes/VERSION

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Version: 2.3.2 (xx-xxx-2014)
44
#81: Serialization of a polymorphic class As.Property with Identity info doesn't work
55
(fixed by Pascal G)
66
-- NOTE! Depends on a related fix in `jackson-databind` 2.3.2
7+
#91: @JsonPropertyOrder not working correctly with attributes
8+
(reported by thrykol@github)
79

810
------------------------------------------------------------------------
911
=== History: ===

src/main/java/com/fasterxml/jackson/dataformat/xml/ser/XmlBeanSerializer.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ protected void serializeFields(Object bean, JsonGenerator jgen0, SerializerProvi
132132

133133
final ToXmlGenerator xgen = (ToXmlGenerator) jgen0;
134134
final BeanPropertyWriter[] props;
135-
// !!! TODO: change to use non-deprecated version in 2.3
136135
if (_filteredProps != null && provider.getActiveView() != null) {
137136
props = _filteredProps;
138137
} else {
@@ -195,7 +194,6 @@ protected void serializeFieldsFiltered(Object bean, JsonGenerator jgen0,
195194
final ToXmlGenerator xgen = (ToXmlGenerator) jgen0;
196195

197196
final BeanPropertyWriter[] props;
198-
// !!! TODO: change to use non-deprecated version in 2.3
199197
if (_filteredProps != null && provider.getActiveView() != null) {
200198
props = _filteredProps;
201199
} else {
@@ -315,17 +313,19 @@ protected static int _orderAttributesFirst(BeanPropertyWriter[] properties,
315313

316314
for (int i = 0, len = properties.length; i < len; ++i) {
317315
BeanPropertyWriter bpw = properties[i];
318-
316+
319317
if (!_isAttribute(bpw)) {
320318
continue;
321319
}
322-
// Swap if attribute and there are preceding elements:
323-
if (attrCount < i) {
324-
properties[i] = properties[attrCount];
320+
321+
// Move attribute a few places done as necessary
322+
int moveBy = i-attrCount;
323+
if (moveBy > 0) {
324+
System.arraycopy(properties, attrCount, properties, attrCount+1, moveBy);
325325
properties[attrCount] = bpw;
326326
if (filteredProperties != null) {
327327
BeanPropertyWriter fbpw = filteredProperties[i];
328-
filteredProperties[i] = filteredProperties[attrCount];
328+
System.arraycopy(filteredProperties, attrCount, filteredProperties, attrCount+1, moveBy);
329329
filteredProperties[attrCount] = fbpw;
330330
}
331331
}

0 commit comments

Comments
 (0)