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

边栏推荐
- Difference between static and final
- Why can't the article be posted?
- 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
- What is the "danksharding" of V God Kop on Valentine's day?
- Honeypot based on MySQL load data local INFILE
- About: deleting unwanted event log lists
- Jenkins operation Chapter 6 mail server sending build results
- Games101 Lecture 10 geometry 1 Notes
- Testing grpc service with grpcui
- Unity AR Shadow 阴影
猜你喜欢
![[high concurrency] deeply analyze the callable interface](/img/fb/89ebd5592f1383c8015a47cec78a59.jpg)
[high concurrency] deeply analyze the callable interface

QT writing map comprehensive application 58 compatible with multi browser kernel

Top ten Devops best practices worthy of attention in 2022

Test Development - ten years of sharpening one sword (VII) interface test tool postman

Longest substring between two identical characters of leetcode simple question

Alphacode made its debut! The programming version of "Alpha dog" competed quietly and defeated half of the programmers

Hustoj SPJ example

Call the computer calculator and use it to convert several base numbers

Summary of redis basic knowledge points

Part 63 - interpreter and compiler adaptation (II)
随机推荐
Servlet version conflict causes page 404
What are the uses of static?
Teach you how to develop your own NPM package (publish to the NPM official website)
Leetcode simple question: judging the color of a grid on a chess board
Honeypot based on MySQL load data local INFILE
Test Development - ten years of sharpening one sword (VII) interface test tool postman
[C language series] - initial C language (4)
Benign competition will promote each other
[C language series] - branch and loop statements
2022-02 Microsoft vulnerability notification
Functions and arrays of shell scripts
It turns out that the joys and sorrows of programmers are not interlinked
VLAN experiment
[MySQL technology topic] technical analysis and guide for analyzing the high availability architecture of MySQL
Review of MySQL knowledge points
Small program large screen adaptation Guide
Two houses with different colors and the farthest distance
JDBC | Chapter 6: simple use of database connection pool
Fault: administrator account cannot be selected for login
How to combine two byte arrays [repeat] - how to combine two byte arrays [duplicate]