Missing type id when trying to resolve subtype of [simple type, class java.lang.Object]: missing type id property '@class'

See original GitHub issue

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 {
        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:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:5

github_iconTop GitHub Comments

12reactions
ergunpcommented, Aug 14, 2019

@gnumilanix I used a completely different approach as what was doing initially was wrong.

3reactions
gnumilanixcommented, Aug 14, 2019

I am trying to configure RedisCacheManager and having a similar issue with GenericJackson2JsonRedisSerializer. Either the one mentioned above or LinkedHashMap 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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found