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

边栏推荐
- [chromium] win10 vs2019 environment chromium configuration and compilation.
- ES6 Modularization: export /import
- Two houses with different colors and the farthest distance
- Functions and arrays of shell scripts
- Hyperledger Fabric 2. X custom smart contract
- String and variable are spliced into variable name
- Plugin
- [C language series] - branch and loop statements
- Teach you how to develop your own NPM package (publish to the NPM official website)
- DANGER! V** caught climbing over the wall!
猜你喜欢

Devops development, operation and maintenance Basics: using Jenkins to automatically build projects and notify by email

QT writing map comprehensive application 58 compatible with multi browser kernel

Regular expressions for shell script values

Teach you how to develop your own NPM package (publish to the NPM official website)

2-nitro-5,10,15,20-tetra (4-methylphenyl) porphyrin copper (no2tmpp) Cu) /2-nitro-5,10,15,20-tetra (4-methylphenyl) porphyrin (no2tmpp) H2) Qiyue porphyrin supply

Top ten Devops best practices worthy of attention in 2022

2-nitro-5,10,15,20-tetra (3,5-dimethoxyphenyl) porphyrin (no2tdmpp) H2) /5,10,15,20-tetra (4-methylphenyl) porphyrin (TMPP) H2) Qiyue porphyrin products
![[high concurrency] deeply analyze the callable interface](/img/fb/89ebd5592f1383c8015a47cec78a59.jpg)
[high concurrency] deeply analyze the callable interface

Pointer from beginner to advanced (2)

Hyperledger Fabric 2. X custom smart contract
随机推荐
What are the uses of static?
Maximum ascending subarray sum of leetcode simple problem
How to combine two byte arrays [repeat] - how to combine two byte arrays [duplicate]
64 commonly used terms for data analysis, really all!
CodeIgniter active record not equal - CodeIgniter active record not equal
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
MySQL add / delete / modify query SQL statement exercise yyds dry goods inventory
Go compile source code (window environment)
CCTV revealed that xumengtao won the black Technology: there was a virtual coach???
JDBC | Chapter 5: closing and releasing JDBC connection resources
I would like to ask what securities dealers recommend? Is it safe to open an account online?
What is the "danksharding" of V God Kop on Valentine's day?
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
Design and practice of kubernetes cluster and application monitoring scheme
Part 63 - interpreter and compiler adaptation (II)
Venn diagram proportional and color shading with semi transparency
Hyperledger Fabric 2. X custom smart contract
ES6 Modularization: export /import
Creation of Arduino uno development environment
Test Development - ten years of sharpening one sword (VII) interface test tool postman