Spring Batch, JdbcExecutionContextDao java.util.Map $ Input deserializer error, xstream 1.4.1

I have a problem using Spring Batch 2.1.9: when I use jobExplorer.getJobExecution (jobExecutionId), I find a problem when the DAO deserializes the string, for example:

{"map":[{"entry":{"string":"parsedComparingDate","date":"2014-03-08 23:00:00.0 UTC"}}]}

from table BATCH_JOB_EXECUTION_CONTEXT using the method JdbcJobExecutionDao.getJobExecution().

I know that Spring package uses xstream 1.3, but in my Pom I:

  • spring -batch 2.1.9 ;
  • xstream 1.4.1 (inherited from smooks);
  • jettison 1.3.3 (inherited from cxf);

In addition, I read that xstream 1.3 does not work fine with Jettison 1.3.3, but using xstream 1.3 (excluding xstream 1.4.1 from pom) the operation works correctly, while using xstream 1.4.1 or major, I I find the following exception:

Caused by: java.lang.InstantiationError: java.util.Map$Entry
        at sun.reflect.GeneratedSerializationConstructorAccessor1.newInstance(Unknown Source) [:1.6.0_23]
        at java.lang.reflect.Constructor.newInstance(Constructor.java:513) [rt.jar:1.6.0_23]
        at com.thoughtworks.xstream.converters.reflection.Sun14ReflectionProvider.newInstance(Sun14ReflectionProvider.java:75) [xstream-1.4.1.jar:]
        at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.instantiateNewInstance(AbstractReflectionConverter.java:424) [xstream-1.4.1.jar:]
        at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:229) [xstream-1.4.1.jar:]
        at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72) [xstream-1.4.1.jar:]
        at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65) [xstream-1.4.1.jar:]
        at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66) [xstream-1.4.1.jar:]
        at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:50) [xstream-1.4.1.jar:]
        at com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter.readItem(AbstractCollectionConverter.java:71) [xstream-1.4.1.jar:]
        at com.thoughtworks.xstream.converters.collections.MapConverter.putCurrentEntryIntoMap(MapConverter.java:85) [xstream-1.4.1.jar:]
        at com.thoughtworks.xstream.converters.collections.MapConverter.populateMap(MapConverter.java:77) [xstream-1.4.1.jar:]
        at com.thoughtworks.xstream.converters.collections.MapConverter.populateMap(MapConverter.java:71) [xstream-1.4.1.jar:]
        at com.thoughtworks.xstream.converters.collections.MapConverter.unmarshal(MapConverter.java:66) [xstream-1.4.1.jar:]
        at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72) [xstream-1.4.1.jar:]
        at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65) [xstream-1.4.1.jar:]
        at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66) [xstream-1.4.1.jar:]
        at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:50) [xstream-1.4.1.jar:]
        at com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller.java:134) [xstream-1.4.1.jar:]
        at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.unmarshal(AbstractTreeMarshallingStrategy.java:32) [xstream-1.4.1.jar:]
        at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1035) [xstream-1.4.1.jar:]
        at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1019) [xstream-1.4.1.jar:]
        at com.thoughtworks.xstream.XStream.fromXML(XStream.java:895) [xstream-1.4.1.jar:]
        at com.thoughtworks.xstream.XStream.fromXML(XStream.java:886) [xstream-1.4.1.jar:]
        at org.springframework.batch.core.repository.dao.XStreamExecutionContextStringSerializer.deserialize(XStreamExecutionContextStringSerializer.java:48) [spring-batch-core-2.1.9.RELEASE.jar:]
        at org.springframework.batch.core.repository.dao.JdbcExecutionContextDao$ExecutionContextRowMapper.mapRow(JdbcExecutionContextDao.java:222) [spring-batch-core-2.1.9.RELEASE.jar:]
        at org.springframework.batch.core.repository.dao.JdbcExecutionContextDao$ExecutionContextRowMapper.mapRow(JdbcExecutionContextDao.java:215) [spring-batch-core-2.1.9.RELEASE.jar:]
        at org.springframework.jdbc.core.RowMapperResultSetExtractor.extractData(RowMapperResultSetExtractor.java:92) [org.springframework.jdbc-3.2.1.RELEASE.jar:3.2.1.RELEASE]
        at org.springframework.jdbc.core.RowMapperResultSetExtractor.extractData(RowMapperResultSetExtractor.java:60) [org.springframework.jdbc-3.2.1.RELEASE.jar:3.2.1.RELEASE]
        at org.springframework.jdbc.core.JdbcTemplate$1.doInPreparedStatement(JdbcTemplate.java:649) [org.springframework.jdbc-3.2.1.RELEASE.jar:3.2.1.RELEASE]
        at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:587) [org.springframework.jdbc-3.2.1.RELEASE.jar:3.2.1.RELEASE]
        at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:637) [org.springframework.jdbc-3.2.1.RELEASE.jar:3.2.1.RELEASE]
        at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:666) [org.springframework.jdbc-3.2.1.RELEASE.jar:3.2.1.RELEASE]
        at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:674) [org.springframework.jdbc-3.2.1.RELEASE.jar:3.2.1.RELEASE]
        at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:714) [org.springframework.jdbc-3.2.1.RELEASE.jar:3.2.1.RELEASE]
        at org.springframework.jdbc.core.simple.SimpleJdbcTemplate.query(SimpleJdbcTemplate.java:202) [org.springframework.jdbc-3.2.1.RELEASE.jar:3.2.1.RELEASE]
        at org.springframework.jdbc.core.simple.SimpleJdbcTemplate.query(SimpleJdbcTemplate.java:209) [org.springframework.jdbc-3.2.1.RELEASE.jar:3.2.1.RELEASE]
        at org.springframework.batch.core.repository.dao.JdbcExecutionContextDao.getExecutionContext(JdbcExecutionContextDao.java:106) [spring-batch-core-2.1.9.RELEASE.jar:]

1) I saw the code, can I configure the XStreamExecutionContextStringSerializer to set reflectionProvider = null (this way it will not use the Provider)?

2) are there any other solutions to solve my problem?

thank

+4
source share
3 answers

It is not possible to change the xstream version and the reset version because they are imported by other components (e.g. smooks).

JBoss .

, : spring -batch 2.2.0.RELEASE org.springframework.batch.core.repository.dao.DefaultExecutionContextSerializer XStream.

:

<bean id="batchDefaultSerializer" class="org.springframework.batch.core.repository.dao.DefaultExecutionContextSerializer" />

<bean id="jobRepository" class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="transactionManager" ref="batchTransactionManager" />
    <property name="lobHandler" ref="defaultLobHandler" />
    <property name="serializer" ref="batchDefaultSerializer" />
</bean>       

<bean id="jobExplorer"      
      class="org.springframework.batch.core.explore.support.JobExplorerFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="serializer" ref="batchDefaultSerializer" />
</bean>

, , .

+4

- Jettison 1.2+ XStream, XStream Spring. , , . Jettison 1.2 XStream 1.4.7

+3

Spring Boot 1.4.0 Spring Batch 3.0.7 , OSS Netflix b/c, XStreams 1.4.2.

I also use Java configuration instead of XML. Here is what I decided to solve the problem: In the @Configuration class:

   @Bean
   public ExecutionContextSerializer serializer()
   {
      return new Jackson2ExecutionContextStringSerializer();
   }

   @Bean
   @Autowired
   public JobRepository jobRepository( DataSource dataSource, 
                                       PlatformTransactionManager txManager ) throws Exception
   {
        JobRepositoryFactoryBean fac = new JobRepositoryFactoryBean();
        fac.setDataSource( dataSource );
        fac.setTransactionManager( txManager );
        fac.setSerializer( serializer() );
        fac.afterPropertiesSet();
        return fac.getObject();
   }

   @Bean
   @Autowired
   public JobExplorer jobExplorer( DataSource dataSource ) throws Exception
   {
      JobExplorerFactoryBean fac = new JobExplorerFactoryBean();
      fac.setDataSource( dataSource );
      fac.setSerializer( serializer() );
      fac.afterPropertiesSet();
      return fac.getObject();
   }

I use Postgres as the backup storage, so DefaultExecutionContextSerializer does not work as it tried to serialize binary instead of UTF-8 (JSON).

+1
source

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


All Articles