自定义redisTemplate<String,Object>后,在使用时,需要在自动注入的RedisTemplate中添加泛型为RedisTemplate<String,Object>,否则会报错:
com.fasterxml.jackson.core.JsonParseException: Unexpected character ('z' (code 122)): Expected space separating root-level values。
添加了泛型没有再报错
二、日期类型序列化问题自定义了RedisTemplate<String,Object>后,当将Redis存储的User对象取出强转为User类型时报错:
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `JAVA.time.LocalDateTime` (no Creators, like default constructor, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
User中的LocalDateTime类型需要指定序列化和反序列化的方式,使用@JsonDeserialize和@JsonSerialize注解:
添加序列化和反序列化注解