use of com.thoughtworks.xstream.converters.reflection.ReflectionProvider in project restfulie-java by caelum.
the class XStreamHelper method getXStream.
/**
* Extension point for configuring your xstream instance.
*
* @param typesToEnhance
* @param list
* @return an xstream instance with support for link enhancement.
*/
@SuppressWarnings("rawtypes")
public XStream getXStream(List<Class> typesToEnhance, List<String> collectionNames) {
ReflectionProvider provider = getProvider();
XStream xstream = new XStream(provider, driver) {
@Override
protected MapperWrapper wrapMapper(MapperWrapper next) {
return new LinkSupportWrapper(next);
}
};
xstream.useAttributeFor(DefaultRelation.class, "rel");
xstream.useAttributeFor(DefaultRelation.class, "href");
xstream.useAttributeFor(DefaultRelation.class, "type");
for (Class type : typesToEnhance) {
realTypes.put(type, enhancer.enhanceResource(type));
xstream.processAnnotations(type);
}
Class enhancedType = enhancer.enhanceResource(EnhancedList.class);
realTypes.put(EnhancedList.class, enhancedType);
for (String name : collectionNames) {
xstream.alias(name, enhancedType);
}
for (Class type : typesToEnhance) {
xstream.addImplicitCollection(enhancedType, "elements", xstream.getMapper().serializedClass(type), type);
}
for (Class customType : realTypes.values()) {
xstream.addImplicitCollection(customType, "link", "link", DefaultRelation.class);
}
return xstream;
}
Aggregations