How to change the default serialization of the framework to my own JSON serialization
See original GitHub issue @Bean("reactiveRedisTemplate")
public ReactiveRedisTemplate<String, Object> ReactiveRedisTemplate() {
GenericFastJsonRedisSerializer jsonRedisSerializer = new GenericFastJsonRedisSerializer();
RedisSerializationContext<Object, Object> serializationContext = RedisSerializationContext
.newSerializationContext().key(jsonRedisSerializer).value(jsonRedisSerializer)
.hashKey(jsonRedisSerializer).hashValue(jsonRedisSerializer).build();
return new ReactiveRedisTemplate(lettuceConnectionFactory(), serializationContext);
}
but I find
org.springframework.session.data.redis.config.annotation.web.server.RedisWebSessionConfiguration
have a private method:
private ReactiveRedisTemplate<String, Object> createReactiveRedisTemplate() {
RedisSerializer<String> keySerializer = new StringRedisSerializer();
RedisSerializer<Object> valueSerializer = new JdkSerializationRedisSerializer(
this.classLoader);
RedisSerializationContext<String, Object> serializationContext = RedisSerializationContext
.<String, Object>newSerializationContext(valueSerializer)
.key(keySerializer).hashKey(keySerializer).build();
return new ReactiveRedisTemplate<>(this.redisConnectionFactory,
serializationContext);
}
,
My configuration does not work at all.
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
How to write custom converters for JSON serialization - .NET
Learn how to create custom converters for the JSON serialization classes that ... To override the default behavior of a built-in converter.
Read more >Setting the default JSON serializer in ASP.NET MVC
In ASP.Net MVC4 the default JavaScript serializer which is used in the JsonResult class is still the JavaScriptSerializer (you can check it in...
Read more >Customize your Java-JSON serialization using Jackson ...
As you can see, Jackson serializes our Java object to JSON including all the “accessible fields” and uses an epoch to represent our...
Read more >Setting JSON Serialization Configuration At Runtime On A ...
Within JSON.net, there isn't any ability for this to do it out of the box. In my case I'm looking to use a...
Read more >JSON Serialization in Rails: A Complete Guide - ButterCMS
The JSON serialization process consists of two stages: data preparation and transformation to the JSON format. Data preparation. Data ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
OK, so as suspected, you’re using Spring Session 2.0.x (i.e. Apple) where we don’t have a first-class support for supplying a custom serialization mechanism.
You have two options; either update to Spring Session 2.1.x (i.e. Bean) - note that we’ve just release
Bean-RELEASE
yesterday; if you cannot upgrade, you need to manually registerReactiveRedisOperationsSessionRepository
and configure it with desiredReactiveRedisTemplate
. For example:When you upgrade the Spring Session 2.1.x (i.e. Bean) you will simply replace the custom
ReactiveRedisOperationsSessionRepository
bean declaration with theRedisSerializer<Object>
namedspringSessionDefaultRedisSerializer
that will be automatically picked up:Does this help?
Thanks for the follow up and kind words @masterchengsheng. Closing this as answered.