Use the JSON deserializer for the context of a batch job

I am trying to get a list of jobs that were stored in Spring tables related to a package in a database using:

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

The above method call calls the ExecutionContextRowMapper.mapRow method in the JdbcExecutionContextDao class.

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

It seems that the incorrect xml deserializer is used by default to unleash the JSONified JobExecutionContext. Is there any configuration to use the JSON deserializer in this scenario.

+6
source share
1 answer

The serializer / deserializer for the ExecutionContext is configured in 2.2.x. We use the ExecutionContextSerializer interface (providing two implementations, one using Java serialization and one using the XStream impl that you mention). To set up your own serializer, you need to implement org.springframework.batch.core.repository.ExecutionContextSerializer and enter it in JobRepositoryFactoryBean (so that contexts are serialized / deserialized correctly) and JobExplorerFactoryBean (to reinitialize previously saved contexts).

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

+3
source

Source: https://habr.com/ru/post/955084/


All Articles