|
6 | 6 |
|
7 | 7 | package nl.b3p.planmonitorwonen.api.configuration; |
8 | 8 |
|
| 9 | +import java.io.InputStream; |
| 10 | +import java.io.ObjectInputStream; |
9 | 11 | import javax.sql.DataSource; |
10 | 12 | import org.springframework.beans.factory.annotation.Qualifier; |
11 | 13 | import org.springframework.beans.factory.annotation.Value; |
12 | 14 | import org.springframework.boot.jdbc.DataSourceBuilder; |
13 | 15 | import org.springframework.context.annotation.Bean; |
14 | 16 | import org.springframework.context.annotation.Configuration; |
15 | 17 | import org.springframework.context.annotation.Profile; |
| 18 | +import org.springframework.core.convert.ConversionService; |
| 19 | +import org.springframework.core.convert.support.GenericConversionService; |
| 20 | +import org.springframework.core.serializer.Deserializer; |
| 21 | +import org.springframework.core.serializer.support.DeserializingConverter; |
| 22 | +import org.springframework.core.serializer.support.SerializingConverter; |
16 | 23 | import org.springframework.jdbc.core.simple.JdbcClient; |
17 | 24 | import org.springframework.jdbc.datasource.DataSourceTransactionManager; |
18 | 25 | import org.springframework.session.jdbc.config.annotation.SpringSessionDataSource; |
@@ -75,4 +82,23 @@ public PlatformTransactionManager springSessionTransactionOperations( |
75 | 82 | @Qualifier("springSessionDataSource") DataSource springSessionDatasource) { |
76 | 83 | return new DataSourceTransactionManager(springSessionDatasource); |
77 | 84 | } |
| 85 | + |
| 86 | + @Bean("springSessionConversionService") |
| 87 | + public ConversionService springSessionConversionService() { |
| 88 | + GenericConversionService converter = new GenericConversionService(); |
| 89 | + converter.addConverter(Object.class, byte[].class, new SerializingConverter()); |
| 90 | + converter.addConverter(byte[].class, Object.class, new DeserializingConverter(new CustomDeserializer())); |
| 91 | + return converter; |
| 92 | + } |
| 93 | + |
| 94 | + static class CustomDeserializer implements Deserializer<Object> { |
| 95 | + @Override |
| 96 | + public Object deserialize(InputStream inputStream) { |
| 97 | + try (ObjectInputStream ois = new ObjectInputStream(inputStream)) { |
| 98 | + return ois.readObject(); |
| 99 | + } catch (Exception ignored) { |
| 100 | + return null; |
| 101 | + } |
| 102 | + } |
| 103 | + } |
78 | 104 | } |
0 commit comments