1 year ago
#365341
shan
Issue regarding jackson- Redis Serialization Exception
Im getting this exception while implementing Redis cache , i have downstream api which i m consuming , its using spring hateoas , it is returning some data but i got exception , looks some kind of serialization - deserialization issue but i have defined custom seralizer for it
Exception: Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Type id handling not implemented for type java.lang.Object (by serializer of type org.springframework.hateoas.EntityModel$MapSuppressingUnwrappingSerializer) (through reference chain: org.springframework.hateoas.EntityModel["content"])
any clue would be appreciated
i used custom serializer for it, didnt work
@Bean("customRedisCacheSerializer") public RedisSerializer<Object> redisSerializer() { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.configure(DeserializationFeature.FAIL_ON_MISSING_CREATOR_PROPERTIES,false); mapper.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES,false); mapper.enable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); mapper.setDefaultPropertyInclusion(JsonInclude.Include.NON_NULL); mapper.activateDefaultTyping(mapper.getPolymorphicTypeValidator(), ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY); mapper.registerModule(new JavaTimeModule());
return new GenericJackson2JsonRedisSerializer(mapper);
}
@Bean
GenericJackson2JsonRedisSerializer genericJackson2JsonRedisSerializer() {
ObjectMapper objectMapper = JsonMapper.builder()
.disable(DeserializationFeature.FAIL_ON_MISSING_CREATOR_PROPERTIES)
.activateDefaultTyping(BasicPolymorphicTypeValidator.builder().allowIfBaseType(Object.class)
.allowIfSubTypeIsArray().build(), ObjectMapper.DefaultTyping.NON_FINAL,
JsonTypeInfo.As.PROPERTY)
.build();
return new GenericJackson2JsonRedisSerializer(objectMapper);
}
....
config.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(customRedisCacheSerializer));
java
spring
serialization
redis
spring-hateoas
0 Answers
Your Answer