I am trying to move some user settings to a cache in Redis. In the current solution, the settings are cached in the app memory as:
private final Cache<Integer, Map<Integer, Object>> userSettingsCache;
The key here is of course the userId, while the value is a map of where Integer describes an index of setting-type and Object can be one of different setting types - CountrySettings, LanguageSettings etc.
I would like to move this cache to Redis. However I encounter a problem when trying to load the cached values back from Redis. The problem is with the deserialization, here is the error message:
org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [byte[]] to type [com.example.demo.CountrySettings]
This is the class describing the settings I save in Redis:
@RedisHash("UserSettings")
public class UserSettings implements Serializable {
@Id
private String id;
private Map<Integer, Object> map;
}
the code I use for saving the object:
Map<Integer, Object> map = new HashMap<>();
map.put(1, new CountrySettings(1L, "UK", "United Kingdom"));
map.put(2, new LanguageSettings(3L, "English"));
settingsRedisRepository.save(new UserSettings("someId1", map));
the code i use for retrieving the object:
settingsRedisRepository.findById("someId1").orElse(null);
I use spring-data-redis.
I tried using different custom deserializers between byte[] and Object, but none of it worked. Has anyone had this problem?