![]() |
|
|
|
|
Issue Type:
|
Bug
|
|
Affects Versions:
|
1.4.3 |
|
Assignee:
|
Jörg Schaible
|
|
Components:
|
Compatibility |
|
Created:
|
13/Dec/12 11:18 AM
|
|
Description:
|
Recently I had to add this little gem to my code:
/**
- This Class is a TreeMap with compare that restores the xstream 1.2 attribute order behaviour.
- It is a fix/workaround for com.thoughtworks.xstream.converters.reflection.XStream12FieldKeySorter ,which is broken in xstream 1.4.3 by this bug:
- in: com.thoughtworks.xstream.converters.reflection.FieldDictionary
public Field fieldOrNull(Class cls, String name, Class definedIn) {
Map fields = buildMap(cls, definedIn != null);
Field field = (Field)fields.get(definedIn != null
? (Object)new FieldKey(name, definedIn, 0) // <- bad idea, set the order 0 in the Key object for the get(). order is used in the compare() of our TreeMap
: (Object)name);
return field;
}
- @author Bouke
*
*/
public static class XStream12FieldKeySorterFixed implements FieldKeySorter {
@SuppressWarnings("unchecked")
public Map sort(final Class type, final Map keyedByFieldKey) {
final Map map = new TreeMap(new Comparator() {
public int compare(final Object o1, final Object o2) {
final FieldKey fieldKey1 = (FieldKey)o1;
final FieldKey fieldKey2 = (FieldKey)o2;
if( fieldKey1.equals(fieldKey2) )//xstream bug fix: search FieldKeys are created with order = 0.
return 0;
int i = fieldKey2.getDepth() - fieldKey1.getDepth();
if (i == 0) {
//xstream bug fix: search FieldKeys are created with order = 0.
//i = fieldKey1.getOrder() - fieldKey2.getOrder();
Field[] classVars = fieldKey1.getDeclaringClass().getDeclaredFields();
int order;
for(order = 0; order < classVars.length && !classVars[order].getName().equals(fieldKey1.getFieldName() ) ; order++ ){
//nothing to do
}
return (order - fieldKey2.getOrder() );
//end of bug fix
}
return i;
}
});
map.putAll(keyedByFieldKey);
return map;
}
|
|
Project:
|
XStream
|
|
Priority:
|
Minor
|
|
Reporter:
|
Bouke de Vries
|
|
|
|
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators.
For more information on JIRA, see: http://www.atlassian.com/software/jira
|
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email