Java Code Examples for com.thoughtworks.xstream.XStream#addDefaultImplementation()

The following examples show how to use com.thoughtworks.xstream.XStream#addDefaultImplementation() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SerializerServiceBase.java    From rice with Educational Community License v2.0 6 votes vote down vote up
public SerializerServiceBase() {
    serializationStates = new ThreadLocal<SerializationState>();
    evaluators = new ThreadLocal<PropertySerializabilityEvaluator>();

    xstream = new XStream(new ProxyAndStateAwareJavaReflectionProvider());
    xstream.registerConverter(new ProxyConverter(xstream.getMapper(), xstream.getReflectionProvider() ));
    try {
    	Class<?> objListProxyClass = Class.forName("org.apache.ojb.broker.core.proxy.ListProxyDefaultImpl");
        xstream.addDefaultImplementation(ArrayList.class, objListProxyClass);
        xstream.addDefaultImplementation(AutoPopulatingList.class, objListProxyClass);
    } catch ( Exception ex ) {
    	// Do nothing - this will blow if the OJB class does not exist, which it won't in some installs
    }
    xstream.registerConverter(new AutoPopulatingListConverter(xstream.getMapper()));
    xstream.registerConverter(new DateTimeConverter());
}
 
Example 2
Source File: XmlObjectSerializerIgnoreMissingFieldsServiceImpl.java    From rice with Educational Community License v2.0 5 votes vote down vote up
public XmlObjectSerializerIgnoreMissingFieldsServiceImpl() {

        xstream = new XStream(new ProxyAwareJavaReflectionProvider()) {
            @Override
            protected MapperWrapper wrapMapper(MapperWrapper next) {
                return new MapperWrapper(next) {
                    @Override
                    public boolean shouldSerializeMember(Class definedIn,
                            String fieldName) {
                        if (definedIn == Object.class) {
                            return false;
                        }
                      return super.shouldSerializeMember(definedIn, fieldName);
                   }
               };
           }
       };

		xstream.registerConverter(new ProxyConverter(xstream.getMapper(), xstream.getReflectionProvider() ));
        try {
        	Class<?> objListProxyClass = Class.forName("org.apache.ojb.broker.core.proxy.ListProxyDefaultImpl");
            xstream.addDefaultImplementation(ArrayList.class, objListProxyClass);
        } catch ( Exception ex ) {
        	// Do nothing - this will blow if the OJB class does not exist, which it won't in some installs
        }
        xstream.registerConverter(new DateTimeConverter());
	}
 
Example 3
Source File: XmlObjectSerializerServiceImpl.java    From rice with Educational Community License v2.0 5 votes vote down vote up
public XmlObjectSerializerServiceImpl() {
		xstream = new XStream(new ProxyAwareJavaReflectionProvider());

        // See http://xstream.codehaus.org/faq.html#Serialization_CGLIB
        // To use a newer version of XStream we may need to do something like this:
//        xstream = new XStream() {
//
//            @Override
//            public ReflectionProvider getReflectionProvider() {
//                return new ProxyAwareJavaReflectionProvider();
//            }
//
//            protected MapperWrapper wrapMapper(MapperWrapper next) {
//                return new CGLIBMapper(next);
//            }
//        };
//        xstream.registerConverter(new CGLIBEnhancedConverter(xstream.getMapper(), xstream.getReflectionProvider()));

		xstream.registerConverter(new ProxyConverter(xstream.getMapper(), xstream.getReflectionProvider() ));
        try {
        	Class<?> objListProxyClass = Class.forName("org.apache.ojb.broker.core.proxy.ListProxyDefaultImpl");
            xstream.addDefaultImplementation(ArrayList.class, objListProxyClass);
        } catch ( Exception ex ) {
        	// Do nothing - this will blow if the OJB class does not exist, which it won't in some installs
        }
        xstream.registerConverter(new DateTimeConverter());
	}
 
Example 4
Source File: XmlApiResponse.java    From engage-api-client with Apache License 2.0 5 votes vote down vote up
private XStream prepareXStream(Class<? extends ApiResult> resultClass) {
	XmlApiReflectionProvider reflectionProvider = new XmlApiReflectionProvider(resultClass);
	XStream xStream = xStreamFactory.createXStream(reflectionProvider);
	
	xStream.processAnnotations(XmlApiResponseEnvelope.class);		
	xStream.addDefaultImplementation(resultClass, ApiResponse.class);
	xStream.processAnnotations(resultClass);

	return xStream;
}