use of com.thoughtworks.xstream.converters.collections.PropertiesConverter in project maven-plugins by apache.
the class EvaluateMojo method getXStream.
/**
* @return lazy loading xstream object.
*/
private XStream getXStream() {
if (xstream == null) {
xstream = new XStream();
addAlias(xstream);
// handle Properties a la Maven
xstream.registerConverter(new PropertiesConverter() {
/** {@inheritDoc} */
public boolean canConvert(@SuppressWarnings("rawtypes") Class type) {
return Properties.class == type;
}
/** {@inheritDoc} */
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
Properties properties = (Properties) source;
// sort
Map<?, ?> map = new TreeMap<Object, Object>(properties);
for (Map.Entry<?, ?> entry : map.entrySet()) {
writer.startNode(entry.getKey().toString());
writer.setValue(entry.getValue().toString());
writer.endNode();
}
}
});
}
return xstream;
}
Aggregations