Search in sources :

Example 1 with ReflectionProvider

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;
}
Also used : MapperWrapper(com.thoughtworks.xstream.mapper.MapperWrapper) XStream(com.thoughtworks.xstream.XStream) Sun14ReflectionProvider(com.thoughtworks.xstream.converters.reflection.Sun14ReflectionProvider) ReflectionProvider(com.thoughtworks.xstream.converters.reflection.ReflectionProvider)

Aggregations

XStream (com.thoughtworks.xstream.XStream)1 ReflectionProvider (com.thoughtworks.xstream.converters.reflection.ReflectionProvider)1 Sun14ReflectionProvider (com.thoughtworks.xstream.converters.reflection.Sun14ReflectionProvider)1 MapperWrapper (com.thoughtworks.xstream.mapper.MapperWrapper)1