spring-projects / spring-projects/spring-data-redis
Radis deserialise json on update InvalidTypeIdException [DATAREDIS-928]
@christophstrobl is already working on this.
Since Dec 30, 2020.
- Dominant language
- Java
- Stars
- 1.9k
- Forks
- 1.3k
- PR merge metrics
- No merged PRs in 30d
Description
ergunp opened DATAREDIS-928 and commented
Hi,
I am using Redis with Spring boot 2 and Kotlin. I am having an issue updating an entry in Redis.
I am storing my object as json in redis cache using the
GenericJackson2JsonRedisSerializer()
But my issue is when I try to update the object within the cache I get the following error
Caused by: com.fasterxml.jackson.databind.exc.InvalidTypeIdException: Missing type id when trying to resolve subtype of [simple type, class java.lang.Object]: missing type id property '@class'
at [Source: (byte[])"{"id":"10.36.55.1","protocolRestriction":false}"; line: 1, column: 47]
I have already tried adding the following to my object.
@JsonTypeInfo(
use = JsonTypeInfo.Id.MINIMAL_CLASS,
include = JsonTypeInfo.As.PROPERTY,
property = "@class")
but with no luck.
Here is my config,
@Bean
fun redisCacheManager(objectMapper: ObjectMapper): CacheManager
{ val jsonSerializer = RedisSerializationContext.SerializationPair .fromSerializer(GenericJackson2JsonRedisSerializer()) return RedisCacheManager.RedisCacheManagerBuilder .fromConnectionFactory(jedisConnectionFactory()) .cacheDefaults( RedisCacheConfiguration.defaultCacheConfig() .entryTtl(Duration.ofMinutes(cacheTimeToLive!!)) .serializeValuesWith(jsonSerializer)) .build() }
this is my object
@RedisHash("sessionState", timeToLive = 900) //evict after 15min
data class SessionState(@Id val id:String?,
val protocolRestriction: Boolean?): Serializable
Here is how i am updating my object in the cache
@Caching(put = CachePut("sessionStateCache", key = "#sessionState.id", unless = "#result == null"),
evict = [CacheEvict("allSessionStateCache", allEntries = true)])
override fun updateSessionState(sessionState: SessionState): SessionState
{ return sessionStateRepo.save(sessionState) }
Any help would be much appreciated
No further details from DATAREDIS-928
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.