title: How can I easily cache Kotlin Objects in Redis using json via Jackson?
body: <p>I have a Spring boot app written in Kotlin where I would like to enable caching in Redis. I'd like to have the objects stored as serialized JSON and ideally don't want to have to register each type that could be potentially cached. I have some configuration that mostly works, with a big caveat.</p>
  
  <pre><code>@Bean
  fun redisCacheConfiguration(): RedisCacheConfiguration {
      val objectMapper =
          ObjectMapper()
              .registerModule(KotlinModule())
              .registerModule(JavaTimeModule())
              .enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY)
  
      val serializer = GenericJackson2JsonRedisSerializer(objectMapper)
  
      return RedisCacheConfiguration
          .defaultCacheConfig()
          .serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(serializer))
  }
  </code></pre>
  
  <p>I'm having a little trouble understanding the different values for <code>DefaultTyping</code> but <code>NON_FINAL</code> seems to be the most expansive. However, since objects in Kotlin are final by default, this only works for objects flagged as "open". Ideally I'd like to avoid having to "open" objects just so they can be cached.</p>
  
  <p>Is there some other way I can make this work?</p>