Missing type id when trying to resolve subtype of [simple type, class java.lang.Object]: missing type id property '@class'
See original GitHub issueI 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 {
objectMapper.registerModule(KotlinModule())
objectMapper.enableDefaultTypingAsProperty(ObjectMapper.DefaultTyping.NON_FINAL, "@class")
val jsonSerializer = RedisSerializationContext.SerializationPair
.fromSerializer(GenericJackson2JsonRedisSerializer(objectMapper))
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.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:5
Top Results From Across the Web
Jackson 3.1.1 Missing Type ID of Subtype Exception for ...
Jackson 3.1.1 Missing Type ID of Subtype Exception for Polymorphic Type of List? ... I have a concrete object of an abstract class...
Read more >Typed object throws "Missing type id" when annotated with ...
And I'm getting, InvalidTypeException: Missing type id when trying to resolve subtype of [simple type, class Bike]: missing type id property ' ...
Read more >JsonTypeInfo (Jackson-annotations 2.8.0 API) - FasterXML
Annotation used for configuring details of if and how type information is used with JSON serialization and deserialization, to preserve information about ...
Read more >Inheritance in Jackson | Baeldung
This tutorial will demonstrate how to handle inclusion of subtype metadata and ignoring properties inherited from superclasses with Jackson.
Read more >Kotlin and Jackson - Missing type id when trying to resolve ...
[Solved]-Kotlin and Jackson - Missing type id when trying to resolve subtype of simple type-kotlin ... first, at the JsonTypeInfo you need to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@gnumilanix I used a completely different approach as what was doing initially was wrong.
I am trying to configure
RedisCacheManager
and having a similar issue withGenericJackson2JsonRedisSerializer
. Either the one mentioned above orLinkedHashMap cannot be cast to com.x.y.z
. This only happens when using@Cacheable
annotation.Are you able to configure it correctly with cache annotations? Or using
RedisTemplate
directly. Would you mind sharing your approach?