-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The model classes generated using delivery-sdk-generators don't extend Serializable interface hence not able cache those entries at client side. #148
Comments
Hello @yayatitech, could you specify your use case? And also what cache you want to use? I am trying to find a scalable solution, instead of adding a new parameter that adds extension from the |
I just want to cache the result from Kontent.ai in my local using following logic in Java Spring client application. Since this ContentItem class is not Serializable, the below method call fails.
I think making all the model (POJO) classes extend Serializable would solve the problem. Serializable doesn't require to implement any method but it marks class can be serialized. Also, the generated classes using delivery-sdk-generators should also extend Serializable. |
Hello @yayatitech, I drafted a serialization support for the generator in #149. I am not sure whether it requires making I can release this as a beta and ask you to test it out with your scenario. Do you have any opinion on testing this serialization in unit tests? Do you think basic serialization and deserialization back and forth and checking the values would be sufficient? Or is the Redis caching technique special somehow in your use case? |
Thanks @Simply007 I think not only This is not related to Redis, basic serialization and deserialization test should be fine. I don't know how it can be tested through unit test though. |
Thanks @yayatitech, This might solve the issue, but I would like to be able to reproduce the issue and then test out the fix. I have tried to set up the least basic implementation of the caching to the spring boot sample app based on the Serializable To reproduce the issue it would require Redis instead of Redis on Java stack is not my strong field. Can you provide me with a simple reproducible setup we can use? Based on this stack overflow thread it should be possible to rewrite the default serializer - would this be sufficient for you? There is also a (caching capability right in the delivery SDK](https://github.com/kontent-ai/java-packages/blob/master/delivery-sdk/src/main/java/kontent/ai/delivery/DeliveryClient.java#L378) - would it be something you could use? |
I have created a pull request with redis cache |
"org.springframework.data.redis.serializer.SerializationException: Cannot serialize; nested exception is org.springframework.core.serializer.support.SerializationFailedException: Failed to serialize object using DefaultSerializer; nested exception is java.io.NotSerializableException: kontent.ai.delivery.TextElement\n\tat org.springframework.data.redis.serializer Since |
Hello @yayatitech, I tried my best to test this out. I have created a Redis cache on redis labs. I was able to reproduce the issue and then set all classes based on Then I got an error that I also need to mark After that, I got the error requesting to mark
All of these you can test out on commit d0b5b4b. |
I did some digging and I was able to re-use the Jackson configuration which is already implemented in Delivery SDK and I was able to get it running 🎉 by configuring it like that: @Bean
public RedisCacheManager cacheManager(RedisConnectionFactory redisConnectionFactory) {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.enable(JsonGenerator.Feature.IGNORE_UNKNOWN);
objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
objectMapper.registerModule(new JavaTimeModule());
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
RedisSerializer<Object> serializer = new GenericJackson2JsonRedisSerializer(objectMapper);
RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig()
.serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer()))
.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(serializer))
.entryTtl(Duration.ofMinutes(1));
return RedisCacheManager.builder(redisConnectionFactory)
.cacheDefaults(config)
.build();
} You can check the sample app implementation in accb089. I think this approach is more suitable for implementation for Redis if you want to use embedded support from Springboot. Still, I think it might be more future-proof to use the embedded capability of delivery SDK for caching and using a custom implementation of the Cache manager using Redis. |
Hello @yayatitech, what do you think about the suggested solution above? I would make this a practice. |
Hi @yayatitech! This issue has gone quiet. 👻 If we missed anything on this issue or if you want to keep it open, please reply here. For now, we will consider this approach as a practice for Redis and Spring: #148 (comment) Thanks for being a part of the Kontent.ai community! |
Motivation
Why is this feature required? What problems does it solve?
Proposed solution
An ideal solution for the above problems.
Additional context
Add any other context, screenshots, or reference links about the feature request here.
The text was updated successfully, but these errors were encountered: