Now I am storing the app user info in redis, the data in redis look like this:
["misc.contract.common.auth.LoginUserInfoDTO", {"userId": 92,"nickname": "u_qCX2J09hAB12","avatarUrl": null,"autoRenewProductExpireTimeMs": null,"appName": "xSW5a4BbVB","thirdBind": ["java.util.ArrayList", [ ["misc.contract.common.auth.ThirdBindInfo", {"id": 3,"channelType": 2,"userId": 92,"thirdUserId": "2088402558023287" } ] ] ] }]
when I tried to read the data in spring boot like this:
package com.example.demo;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.data.redis.core.RedisTemplate;import org.springframework.data.redis.core.ValueOperations;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.RequestMapping;import javax.annotation.PostConstruct;@Controller@RequestMapping("/post/")public class DemoController { @Autowired private RedisTemplate<String, LoginUserInfoDTO> redisTemplate; private ValueOperations<String, LoginUserInfoDTO> loginInfoRedis; @PostConstruct public void init() { this.loginInfoRedis = redisTemplate.opsForValue(); } @GetMapping("/user") String getQRCodeUrl(){ try { LoginUserInfoDTO dto = loginInfoRedis.get("REDDWARF_CV_WEB:user:detail:92"); }catch (Exception e){ System.out.println(e); } return "hello world"; }}
shows error:
Could not read JSON: Could not resolve type id 'misc.contract.common.auth.LoginUserInfoDTO' as a subtype of `java.lang.Object`: no such class found at [Source: (byte[])"["misc.contract.common.auth.LoginUserInfoDTO",{"userId":92,"nickname":"u_qCX2J09hAB12","avatarUrl":null,"autoRenewProductExpireTimeMs":null,"appName":"xSW5a4BbVB","thirdBind":["java.util.ArrayList",[["misc.contract.common.auth.ThirdBindInfo",{"id":3,"channelType":2,"userId":92,"thirdUserId":"2088402558023287"}]]]}]"; line: 1, column: 47]
is that my LoginUserInfoDTO
class not in the namespace misc.contract.common.auth.LoginUserInfoDTO
cause this issue? is it possible to avoid this problem. For example, I saved the user info namespace is misc.contract.common.auth.LoginUserInfoDTO
, the next version I changed the LoginUserInfoDTO
class path, the new version of app could not parse the old version json? this issue will occure in the application runtime? if I only store a plan json without any class info, that is a better choice?