当前位置:网站首页>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

边栏推荐
- How to use regex in file find
- Servlet version conflict causes page 404
- Alphacode made its debut! The programming version of "Alpha dog" competed quietly and defeated half of the programmers
- Ctrip launched the "3+2" office mode. Are you sour?
- Difference between static and final
- QT writing map comprehensive application 58 compatible with multi browser kernel
- Regular expressions for shell script values
- Fault: ntfrs warning log for id13562
- The most complete machine learning model training process
- Servlet version conflict causes page 404
猜你喜欢

Longest substring between two identical characters of leetcode simple question

Monitor employee turnover dynamics. This system makes employees tremble!

Design and practice of kubernetes cluster and application monitoring scheme

Hyperledger Fabric 2. X custom smart contract

What are the uses of wireless pressure collectors?

Establishing the development environment of esp8266

Fault: ntfrs warning log for id13562

Rich material libraries make modeling easy and efficient for developers

2022.02.15 - 240. Lucky number in matrix

Conditional test, if and case conditional test statements of shell script
随机推荐
CodeIgniter active record not equal - CodeIgniter active record not equal
Fault: KDC warning log for id29
QT (x): control operation
Overlay histogram with density curve
Fault: administrator account cannot be selected for login
The most complete machine learning model training process
Week 10 - task 3- from point to circle to cylinder
Pytest (7) -yield and termination function
Slot
Pointer from beginner to advanced (2)
想请教一下,究竟有哪些劵商推荐?在线开户是安全么?
QT writing map comprehensive application 58 compatible with multi browser kernel
ASP. Net core 6 framework unveiling example demonstration [03]:dapr initial experience
Functions and arrays of shell scripts
3 frequently tested SQL data analysis questions (including data and code)
National Defense University project summary
Week 10 - task 1- fill in the blank: line class inherits point class
Leetcode theme [array] -217- there are duplicate elements
What should I learn before learning programming?
Aging design guide for applets