Hi,
if I remember correctly the deserialization support comes with spring 3.x, you can however add a naming interface with the readResolve-method and implement your own aspect. I did that once, but then upgraded to spring 3.x.
Regards
Jakob
Edit: Some example code, I just found:
Code:
package eu.codecamp.utils.lib.aspects.spring;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
@Aspect
public class DeserializeDependencyInjectionAspect {
private static final Log log = LogFactory.getLog(DeserializeDependencyInjectionAspect.class);
@SuppressWarnings("rawtypes")
private Map<Class, IDeserializeDependencyInjector> injectorMap;
@SuppressWarnings("rawtypes")
public DeserializeDependencyInjectionAspect() {
injectorMap = new HashMap<Class, IDeserializeDependencyInjector>();
}
@SuppressWarnings("rawtypes")
public void setInjectors(
List<IDeserializeDependencyInjector> injectors) {
injectorMap.clear();
for (IDeserializeDependencyInjector injector : injectors) {
try {
Type injectorType = injector.getClass().getGenericInterfaces()[0];
Class targetClass = (Class)((ParameterizedType)injectorType).getActualTypeArguments()[0];
injectorMap.put(targetClass, injector);
} catch (ClassCastException e) {
log.error(e);
}
}
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@After("execution(Object eu.codecamp.utils.lib.domain.IDeserializationSupport.readResolve() throws java.io.ObjectStreamException)")
public void injectDependencies(JoinPoint jp) {
try {
Object target = jp.getTarget();
Class targetClass = target.getClass();
if (injectorMap.containsKey(targetClass)) {
try {
IDeserializeDependencyInjector injector = injectorMap.get(targetClass);
injector.injectDependencies(target);
} catch (ClassCastException e) {
log.error(e);
}
}
} catch (NullPointerException e) {
e.printStackTrace();
}
}
}
Code:
package eu.codecamp.utils.lib.aspects.spring;
public interface IDeserializeDependencyInjector<TargetClass> {
public void injectDependencies(TargetClass target);
}
Code:
package eu.codecamp.utils.lib.domain;
import java.io.ObjectStreamException;
import java.io.Serializable;
public interface IDeserializationSupport extends Serializable {
public Object readResolve() throws ObjectStreamException;
}