I was using Spring batch 4.2.7 and I'd custom ExecutionContextSerializer class using jettison 1.2 and thoughtworks xstream 1.4.20. Serializable class is as follow.
public class XStreamExecutionContextStringSerializer2 implements ExecutionContextSerializer, InitializingBean {
private ReflectionProvider reflectionProvider = null;
private HierarchicalStreamDriver hierarchicalStreamDriver;
private XStream xstream;
public void setReflectionProvider(ReflectionProvider reflectionProvider) {
this.reflectionProvider = reflectionProvider;
}
public void setHierarchicalStreamDriver(HierarchicalStreamDriver hierarchicalStreamDriver) {
this.hierarchicalStreamDriver = hierarchicalStreamDriver;
}
@Override
public void afterPropertiesSet() throws Exception {
init();
}
public synchronized void init() throws Exception {
if (hierarchicalStreamDriver == null) {
Configuration configuration = new Configuration();
this.hierarchicalStreamDriver = new JettisonMappedXmlDriver(configuration);
}
if (reflectionProvider == null) {
xstream = new XStream(hierarchicalStreamDriver);
} else {
xstream = new XStream(reflectionProvider, hierarchicalStreamDriver);
}
}
/**
* Serializes the passed execution context to the supplied OutputStream.
*
* @param context {@link Map} containing the context information.
* @param out {@link OutputStream} where the serialized context information
* will be written.
*
* @see Serializer#serialize(Object, OutputStream)
*/
@Override
public void serialize(Map<String, Object> context, OutputStream out) throws IOException {
Assert.notNull(context, "context is required");
Assert.notNull(out, "An OutputStream is required");
out.write(xstream.toXML(context).getBytes());
}
/**
* Deserializes the supplied input stream into a new execution context.
*
* @param in {@link InputStream} containing the information to be deserialized.
*
* @return a reconstructed execution context
* @see Deserializer#deserialize(InputStream)
*/
@SuppressWarnings("unchecked")
@Override
public Map<String, Object> deserialize(InputStream in) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(in));
StringBuilder sb = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
sb.append(line);
}
return (Map<String, Object>) xstream.fromXML(sb.toString());
}
}
As I've upgraded jettison to 1.5.3, it started failing at deserialization, with following error
JobServiceImpl Error while deserializing execution context: Cannot construct type
---- Debugging information ----
message : Cannot construct type
cause-exception : java.lang.InstantiationException
cause-message : java.util.Map$Entry
construction-type : java.util.Map$Entry
class : java.util.Map$Entry
required-type : java.util.Map$Entry
converter-type : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
path : /map/map/entry
line number : -1
class[1] : java.util.HashMap
required-type[1] : java.util.HashMap
converter-type[1] : com.thoughtworks.xstream.converters.collections.MapConverter
version : 1.4.20
-------------------------------Stack Trace:[Ljava.lang.StackTraceElement;@441bcb7a
I've tried to add use the solution of updating batch*_*job_execution_context and batch_step_execution_context as per below stackoverflow solution, but still it is not working. Can someone please help?
Spring Batch 4.2.4: Unable to deserialize the execution context