use of org.redisson.codec.TypedJsonJacksonCodec in project redisson by redisson.
the class JCacheTest method testJson.
@Test
public void testJson() throws InterruptedException, IllegalArgumentException, URISyntaxException, IOException {
RedisProcess runner = new RedisRunner().nosave().randomDir().port(6311).run();
URL configUrl = getClass().getResource("redisson-jcache.yaml");
Config cfg = Config.fromYAML(configUrl);
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new JavaTimeModule());
cfg.setCodec(new TypedJsonJacksonCodec(String.class, LocalDateTime.class, objectMapper));
Configuration<String, LocalDateTime> config = RedissonConfiguration.fromConfig(cfg);
Cache<String, LocalDateTime> cache = Caching.getCachingProvider().getCacheManager().createCache("test", config);
LocalDateTime t = LocalDateTime.now();
cache.put("1", t);
Assertions.assertEquals(t, cache.get("1"));
cache.close();
runner.stop();
}
use of org.redisson.codec.TypedJsonJacksonCodec in project redisson by redisson.
the class RedissonLocalCachedMapTest method testReadAllValues2.
@Test
public void testReadAllValues2() {
ObjectMapper objectMapper = new JsonJacksonCodec().getObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
Codec codec = new TypedJsonJacksonCodec(String.class, SimpleValue.class, objectMapper);
RLocalCachedMap<String, SimpleValue> map1 = redisson.getLocalCachedMap("test", codec, LocalCachedMapOptions.defaults());
RLocalCachedMap<String, SimpleValue> map2 = redisson.getLocalCachedMap("test", codec, LocalCachedMapOptions.defaults());
map1.put("key", new SimpleValue("3"));
Collection<SimpleValue> s = map1.readAllValues();
assertThat(s).hasSize(1);
Collection<SimpleValue> s2 = map2.readAllValues();
assertThat(s2).hasSize(1);
}
Aggregations