当前位置:网站首页>Redistemplate serialization
Redistemplate serialization
2022-06-22 14:42:00 【wfsm】
redisTemplate By default jdk Serialization scheme , When you save , There will be a bunch of prefixes ,
Write one yourself redisTemplate Change his serialization method
- Use jackson
@Bean
public RedisTemplate<Object,Object> redisTemplate(RedisConnectionFactory redisConnectionFactory){
RedisTemplate<Object, Object> template = new RedisTemplate<>();
template.setConnectionFactory(redisConnectionFactory);
// Set serializer : Use jackson serializers
Jackson2JsonRedisSerializer<Object> serializer = new Jackson2JsonRedisSerializer<>(Object.class);
template.setKeySerializer(new StringRedisSerializer());
template.setHashKeySerializer(new StringRedisSerializer());
template.setValueSerializer(serializer);
template.setHashValueSerializer(serializer);
return template;
}
- Use fastjson
@Bean
public RedisTemplate<Object,Object> redisTemplate(RedisConnectionFactory redisConnectionFactory){
RedisTemplate<Object, Object> template = new RedisTemplate<>();
template.setConnectionFactory(redisConnectionFactory);
FastJsonRedisSerializer<Object> serializer = new FastJsonRedisSerializer<>(Object.class);
template.setKeySerializer(new StringRedisSerializer());
template.setValueSerializer(serializer);
template.setHashKeySerializer(new StringRedisSerializer());
template.setHashValueSerializer(serializer);
return template;
}
Problems encountered :
redis Acquired jackson After serialization, there is a linkedHashmap ,, Need to put LinkedHashMap convert to Corresponding object ,, because springsecurity in User Realized UserDetails , Rewritten many get Method ,, image jackson This serialization tool relies on reflection to identify method properties ,get The method at the beginning is easy to mislead the serialization tool
jackson solve :
- Add annotations to the class
@JsonIgnoreProperties(ignoreUnknown = true) - Except for attribute getter Outside method , Do not use other methods get start
ObjectMapper objectMapper = new ObjectMapper();
User user = objectMapper.readValue(objectMapper.writeValueAsString(obj), User.class);
quote :https://blog.csdn.net/woshisangsang/article/details/108420355
https://blog.csdn.net/huang812561/article/details/124706812
fastjson After serialization , yes JSONObject object , To the original object
fastjson solve
User user = JSON.parseObject(JSON.toJSONString(obj), User.class);
quote :https://blog.csdn.net/qq_34577234/article/details/125199552
边栏推荐
- Seven cattle cloud upload picture
- Database employment consulting system for your help
- Error: Unable to find a match: lrzsz的解决方法
- JS高级程序设计第 4 版:迭代器的学习
- Unity 子线程调用主线程的UI
- How to use SQL to modify in the database & delete
- MySQL learning notes 2022
- Shan Zhiguang, chairman of BSN Development Alliance: DDC can provide the underlying support for the development of China's meta universe industry
- Basic usage and FAQs of jasperreport report report generation tool
- 机器学习之感知机
猜你喜欢

Shan Zhiguang, chairman of BSN Development Alliance: DDC can provide the underlying support for the development of China's meta universe industry

拜登签署两项旨在加强政府网络安全的新法案

Neuron+ekuiper realizes data collection, cleaning and anti control of industrial Internet of things

The diffusion model is crazy again! This time the occupied area is

Fluentd is easy to get started. Combined with the rainbow plug-in market, log collection is faster

天润云上市在即:VC大佬田溯宁大幅减持,预计将套现2.6亿港元

【考研攻略】北京交通大学网络空间安全专业2018-2022年考研数据分析

Specific methods and steps of PROFINET communication between s7-200smart and Fanuc robot

MadCap Flare 2022,语言或格式的文档

Cve - 2022 - 22965 Resume
随机推荐
MadCap Flare 2022,语言或格式的文档
轻松上手Fluentd,结合 Rainbond 插件市场,日志收集更快捷
Deadlock found when trying to get lock; Try restarting transaction
Closure of groovy
VR panoramic shooting breaks the deadlock of traditional propaganda that wild geese pass without leaving traces
Technology practice | scene oriented audio and video call experience Optimization
C#泛型_泛型类
Using pictures to locate app elements sikulix
Chip silicon and streaming technology
Perceptron of machine learning
Data collection: skillfully using Bloom filter to extract data summary
Analysis on data skew of redis slice cluster
Cat agile team coaching workshops - August 20
After reading this article, I will teach you to play with the penetration test target vulnhub - drivetingblues-5
基于SSM框架实现的甜品饮品店前后台管理系统甜品商城蛋糕店【源码+数据库】
基于SSH框架甜品商城管理系统【源码+数据库】
Dessert mall management system based on SSH framework [source code + database]
拜登签署两项旨在加强政府网络安全的新法案
As a passer-by, some advice for programmers who are new to the workplace
天润云上市在即:VC大佬田溯宁大幅减持,预计将套现2.6亿港元