Search in sources :

Example 1 with TypedJsonJacksonCodec

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();
}
Also used : LocalDateTime(java.time.LocalDateTime) RedisProcess(org.redisson.RedisRunner.RedisProcess) Config(org.redisson.config.Config) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) RedisRunner(org.redisson.RedisRunner) URL(java.net.URL) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TypedJsonJacksonCodec(org.redisson.codec.TypedJsonJacksonCodec) BaseTest(org.redisson.BaseTest) Test(org.junit.jupiter.api.Test)

Example 2 with TypedJsonJacksonCodec

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);
}
Also used : Codec(org.redisson.client.codec.Codec) StringCodec(org.redisson.client.codec.StringCodec) JsonJacksonCodec(org.redisson.codec.JsonJacksonCodec) CompositeCodec(org.redisson.codec.CompositeCodec) IntegerCodec(org.redisson.client.codec.IntegerCodec) DoubleCodec(org.redisson.client.codec.DoubleCodec) TypedJsonJacksonCodec(org.redisson.codec.TypedJsonJacksonCodec) JsonJacksonCodec(org.redisson.codec.JsonJacksonCodec) TypedJsonJacksonCodec(org.redisson.codec.TypedJsonJacksonCodec) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TypedJsonJacksonCodec(org.redisson.codec.TypedJsonJacksonCodec) Test(org.junit.jupiter.api.Test)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Test (org.junit.jupiter.api.Test)2 TypedJsonJacksonCodec (org.redisson.codec.TypedJsonJacksonCodec)2 JavaTimeModule (com.fasterxml.jackson.datatype.jsr310.JavaTimeModule)1 URL (java.net.URL)1 LocalDateTime (java.time.LocalDateTime)1 BaseTest (org.redisson.BaseTest)1 RedisRunner (org.redisson.RedisRunner)1 RedisProcess (org.redisson.RedisRunner.RedisProcess)1 Codec (org.redisson.client.codec.Codec)1 DoubleCodec (org.redisson.client.codec.DoubleCodec)1 IntegerCodec (org.redisson.client.codec.IntegerCodec)1 StringCodec (org.redisson.client.codec.StringCodec)1 CompositeCodec (org.redisson.codec.CompositeCodec)1 JsonJacksonCodec (org.redisson.codec.JsonJacksonCodec)1 Config (org.redisson.config.Config)1