当前位置:网站首页>RedisTemplate处理hash整数类型的问题解析
RedisTemplate处理hash整数类型的问题解析
2022-06-29 06:32:00 【kgduu】
1、问题
RedisTemplate在配置时,设置hash的值的序列化为GenericJackson2JsonRedisSerializer,在写入数据时数据类型为Long,但是值比较小。在读取时,赋值给Long类型,会提示java.lang.Integer转为java.lang.Long类型的错误。
2、原因分析
OjbectMapper#readValue(byte[] src, Class<T> valueType)用于读取hash的value值,其会调用_findRootDeserializer来查找序列化器,其调用findRootValueDeserializer来查找序列化。

findRootValueDeserializer会调用DeserializerCache#findValueDeserializer来确定使用哪个Deserializer,其最终是调用DeserializerCache#_createDeserializer2,调用DeserializerFactory#createBeanDeserializer,其实现为BeanDeserializerFactory#createBeanDeserializer

对于Class类型为Object类型的,使用UntypedObjectDeserializer。

在反序列化时,对于数字类型的处理为

如果上下文中有整形相关参数时
- DeserializationFeature.USE_LONG_FOR_INTS时,用Long来表示整数数据
- DeserializationFeature.USE_BIG_INTEGER_FOR_INTS,用大整数来表示整数数据
- 其他情况下,使用JsonParser#getNumberValue来处理整数,ParserBase#getNumberValue会根据当前整数的长度来决定是返回Integer还是Long

边栏推荐
- Why is there a packaging type?
- Ghost in the Log4Shell
- The first commercial spacewalk of mankind is finalized! Musk SpaceX announced a new round of space travel plan, and the American rich became repeat customers
- 力扣每日一题-第30天-1281.整数的各位积和之差
- Go compile source code (window environment)
- 2022.02.15 - 240. Lucky number in matrix
- Skills of writing test cases efficiently
- The generation of leetcode simple questions each character is an odd number of strings
- Subtotal of C language -- basic data types and their representations
- 5,10,15,20-tetra (3,5-dimethoxyphenyl) porphyrin ((tdmpp) H2) /2-nitro-5,10,15,20-tetra (3,5-dimethoxyphenyl) porphyrin copper (no2tdmpp) Cu) supplied by Qiyue
猜你喜欢

Fault: NetBt log for id4321

5,10-di (4-aminophenyl) - 15,20-diphenylporphyrin (cis-dadph2) /5,15-di (4-aminophenyl) - 10,20-diphenylporphyrin (trans-dadph2) / (tri-apph2) supplied by Qiyue

Leetcode simple question: judging the color of a grid on a chess board

Why are keys unordered in golang map

Difference between URI and URL

Leetcode simple problem building arrays with stack operation

Will the order of where conditions in MySQL affect the union index? Will where 1 =1 affect the use of the index? Does where 1 =1 affect the use of indexes?

5,10,15,20-tetra (3,5-dimethoxyphenyl) porphyrin ((tdmpp) H2) /2-nitro-5,10,15,20-tetra (3,5-dimethoxyphenyl) porphyrin copper (no2tdmpp) Cu) supplied by Qiyue

Agile invincible event

Sum of digits under k-ary representation of leetcode simple problem
随机推荐
Overlay histogram with density curve
Fault: ntfrs warning log for id13562
Why is there a packaging type?
What should I learn before learning programming?
Small program large screen adaptation Guide
2022.02.15 - SX10-31. House raiding III
Purple red solid meso tetra (o-alkoxyphenyl) porphyrin cobalt (meso-t (2-rop) PCO) / tetra (n, n-diphenyl-p-amino) phenyl porphyrin (tdpatph2)
Plugin
Monitor employee turnover dynamics. This system makes employees tremble!
QT writing map comprehensive application 58 compatible with multi browser kernel
Call the computer calculator and use it to convert several base numbers
QT (x): control operation
2022-01 Microsoft vulnerability notification
Creation of Arduino uno development environment
What are the uses of static?
5,10-di (4-aminophenyl) - 15,20-diphenylporphyrin (cis-dadph2) /5,15-di (4-aminophenyl) - 10,20-diphenylporphyrin (trans-dadph2) / (tri-apph2) supplied by Qiyue
Easy to understand TCP four waves (multi picture explanation)
力扣每日一题-第30天-1523.位1的个数
QT (x): packaging and deployment
VLAN experiment