springboot 2.3 持久化改动.setObjectMapper方法移除.

     这两天在尝试弄弄springboot集成redis.发现网上很多帖子在说序列化时,所用的json序列化方式中的代码如下:

Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
        ObjectMapper om = new ObjectMapper();
        om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
        om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
        jackson2JsonRedisSerializer.setObjectMapper(om);

 本人用的是现在最新的springboot2.3.0办法,跟踪源码发现很多东西变了.不bb直接上相关代码:

ObjectMapper om = new ObjectMapper();
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
om.activateDefaultTyping(LaissezFaireSubTypeValidator.instance ,
        ObjectMapper.DefaultTyping.NON_FINAL);
GenericJackson2JsonRedisSerializer jackson2JsonRedisSerializer = new GenericJackson2JsonRedisSerializer(om);
template.setValueSerializer(jackson2JsonRedisSerializer);
template.setHashValueSerializer(jackson2JsonRedisSerializer);

 

你可能感兴趣的:(springboot,redis,springboot2.3,redis,springboot,springboot2.3)