private String convertToXml(Object obj) {
writerStack.reset();
if (obj instanceof Map) {
Map<?, ?> m = (Map<?, ?>) obj;
ConverterConfig cc = converterMap
.get(XStreamConfiguration.ConverterSet.MAP);
if (m.size() == 1) {
Object s = m.values().iterator().next();
cc.mapper.setBaseObject(s); // thread safe method
String result = cc.xstream.toXML(s);
log.debug("Result is " + result);
return "<response>" + result + "</response>";
}
} else if (obj instanceof RestfulCollection) {
ConverterConfig cc = converterMap
.get(XStreamConfiguration.ConverterSet.COLLECTION);
cc.mapper.setBaseObject(obj); // thread safe method
String result = cc.xstream.toXML(obj);
log.debug("Result is " + result);
return result;
} else if (obj instanceof DataCollection) {
ConverterConfig cc = converterMap
.get(XStreamConfiguration.ConverterSet.MAP);
cc.mapper.setBaseObject(obj); // thread safe method
String result = cc.xstream.toXML(obj);
log.debug("Result is " + result);
return result;
}
ConverterConfig cc = converterMap
.get(XStreamConfiguration.ConverterSet.DEFAULT);
cc.mapper.setBaseObject(obj); // thread safe method
String result = cc.xstream.toXML(obj);
log.debug("Result is " + result);