Redis获取数据报错Could not read JSON: Unrecognized token 'XXXXX': was expecting ('true', 'false' or 'null'

日前由于公司Redis集群切换,导致一些初始化数据需要重新设置到新的Redis;

使用Redis可视化 RedisDesktopManager进行设置

设置成功,到获取的时候发生异常:

2020-04-02 15:42:05.118 yxcode-merak [http-nio-8080-exec-14] ERROR c.y.y.m.c.handle.ExceptionHandle [ExceptionHandle.java : 223] [17be3573a9be7b9f] - 【系统异常】
Could not read JSON: Unrecognized token 'TM2003250094': was expecting ('true', 'false' or 'null')
 at [Source: [B@62e2fc74; line: 1, column: 25]; nested exception is com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'TM2003250094': was expectin
g ('true', 'false' or 'null')
 at [Source: [B@62e2fc74; line: 1, column: 25]
org.springframework.data.redis.serializer.SerializationException: Could not read JSON: Unrecognized token 'TM2003250094': was expecting ('true', 'false' or 'null'
)
 at [Source: [B@62e2fc74; line: 1, column: 25]; nested exception is com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'TM2003250094': was expectin
g ('true', 'false' or 'null')
 at [Source: [B@62e2fc74; line: 1, column: 25]
        at org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer.deserialize(Jackson2JsonRedisSerializer.java:73)
        at org.springframework.data.redis.core.AbstractOperations.deserializeValue(AbstractOperations.java:318)
        at org.springframework.data.redis.core.AbstractOperations$ValueDeserializingRedisCallback.doInRedis(AbstractOperations.java:58)
        at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:207)
        at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:169)
        at org.springframework.data.redis.core.AbstractOperations.execute(AbstractOperations.java:91)
        at org.springframework.data.redis.core.DefaultValueOperations.get(DefaultValueOperations.java:43)

 

经最后发现由于项目Redis配置有关,配置如下:

发现value使用了json序列化,导致上面直接设置的value字符串序列化时报解析json异常;

解决方法:1、将Redis配置修改掉  2、设置值的时候将值加上引号,如

  • 8
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
org.springframework.data.redis.serializer.SerializationException是一个反序列化异常,表示在将JSON字符串转换为对象时出现了问题。具体地说,"Unrecognized field"意味着JSON字符串中包含了无法识别的字段。 这个异常通常发生在使用Spring框架的Redis序列化器时,它试图将JSON字符串反序列化为Java对象。在你提供的引用中,出现了两个例子,它们都是由于JSON字符串中的字段与Java对象的属性不匹配而引发了异常。 为了解决这个问题,你可以采取以下几个方法: 1. 使用@JsonIgnoreProperties(ignoreUnknown = true)注解 这个注解可以在类级别上使用,用于告诉Jackson JSON库在反序列化过程中忽略未知的JSON字段。在你的问题中,你可以在相关的Java类上加上这个注解以忽略无法识别的字段。 2. 使用@JsonIgnore注解 另一种解决方法是在相关的setter、getter或is方法上使用@JsonIgnore注解。这个注解可以用来忽略指定的属性,在反序列化时不会将其考虑在内。 综上所述,你可以根据具体情况选择其中一种方法来解决org.springframework.data.redis.serializer.SerializationException: Could not read JSON: Unrecognized field异常。通过使用@JsonIgnoreProperties(ignoreUnknown = true)注解或在相关方法上使用@JsonIgnore注解,你可以告诉序列化器忽略无法识别的字段,从而避免这个异常的发生。 : org.springframework.data.redis.serializer.SerializationException: Could not read JSON: Unrecognized field : org.springframework.data.redis.serializer.SerializationException: Could not read JSON: Unrecognized field "accountNonLocked" : 解决办法:在类加上注解@JsonIgnoreProperties(ignoreUnknown = true)忽略实体中没有对应的json的key值,或者在set、get或is开头的方法上加上@JsonIgnore注解。
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值