Hi Marvin,
unfortunately most of the stuff for tweaking the XML does only work for the generic converters that are based on reflection. For the TreeSet XStream delivers a custom converter that writes content in synthetic tags i.e. those tags have nothing to do with the real names of the fields within a class. TreeSet is part of the JDK and every vendor can use an own name for the field keeping the Comparator (and they do) and XStream.omitField cannot help you, since you have to provide the declaring class and the name of the field. This is why XStream's own TreeSetConverters does not support this functionality.
To solve your problem and to get rid of the comparator element, you may simply register for the TreeSet a "standard" CollectionConverter that does not know anything about the availability of such an element:
xstream.registerConverter(new CollectionConverter(xstream.getMapper()){
boolean canConvert(Class type) {
return type == TreeSet.class;
}
});
Hi Marvin,
unfortunately most of the stuff for tweaking the XML does only work for the generic converters that are based on reflection. For the TreeSet XStream delivers a custom converter that writes content in synthetic tags i.e. those tags have nothing to do with the real names of the fields within a class. TreeSet is part of the JDK and every vendor can use an own name for the field keeping the Comparator (and they do) and XStream.omitField cannot help you, since you have to provide the declaring class and the name of the field. This is why XStream's own TreeSetConverters does not support this functionality.
To solve your problem and to get rid of the comparator element, you may simply register for the TreeSet a "standard" CollectionConverter that does not know anything about the availability of such an element: