Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use JSON deserializer for Batch job execution context

I'm trying to get a list of job executions which have been stored in Spring batch related tables in the database using:

List<JobExecution> jobExecutions = jobExplorer.getJobExecutions(jobInstance);

The above method call seems to invoke ExecutionContextRowMapper.mapRow method in JdbcExecutionContextDao class.

The ExecutionContextRowMapper uses com.thoughtworks.xstream.Xstream.fromXML method to deserialize the JSON string of JobExecutionContext stored in DB.

It looks like an incorrect or default xml deserializer is used for unmarshalling JSONified JobExecutionContext. Is there any configuration to use a JSON deserializer in this scenario.

like image 420
sireesh Avatar asked Oct 02 '13 09:10

sireesh


1 Answers

The serializer/deserializer for the ExecutionContext is configurable in 2.2.x. We use the ExecutionContextSerializer interface (providing two implementations, one using java serialization and one using the XStream impl you mention). To configure your own serializer, you'll need to implement the org.springframework.batch.core.repository.ExecutionContextSerializer and inject it into the JobRepositoryFactoryBean (so that the contexts are serialized/deserialized correctly) and the JobExplorerFactoryBean (to reserialize the previously saved contexts).

It is important to note that changing the serialization method will prevent Spring Batch from deserializing previously saved ExecutionContexts.

like image 109
Michael Minella Avatar answered Oct 02 '22 02:10

Michael Minella