diff --git a/pom.xml b/pom.xml index 75227f5ef1a4dafafe6fdb24d560dfed2f2d8032..3bfeaa23f29481ea998419cb8b2f401affb041ef 100644 --- a/pom.xml +++ b/pom.xml @@ -214,6 +214,18 @@ 2.6.5 provided + + com.fasterxml.jackson.dataformat + jackson-dataformat-smile + 2.6.5 + provided + + + com.fasterxml.jackson.dataformat + jackson-dataformat-avro + 2.6.5 + provided + net.openhft zero-allocation-hashing diff --git a/src/main/java/org/redisson/codec/AvroJacksonCodec.java b/src/main/java/org/redisson/codec/AvroJacksonCodec.java new file mode 100644 index 0000000000000000000000000000000000000000..4994bbd64d9d41bb4860166179fc8e3ccd52449d --- /dev/null +++ b/src/main/java/org/redisson/codec/AvroJacksonCodec.java @@ -0,0 +1,37 @@ +/** + * Copyright 2016 Nikita Koksharov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.redisson.codec; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.dataformat.avro.AvroFactory; + +/** + * Avro binary codec + * + * @author Nikita Koksharov + * + */ +public class AvroJacksonCodec extends JsonJacksonCodec { + + public AvroJacksonCodec() { + super(new ObjectMapper(new AvroFactory())); + } + + public AvroJacksonCodec(ClassLoader classLoader) { + super(createObjectMapper(classLoader, new ObjectMapper(new AvroFactory()))); + } + +} diff --git a/src/main/java/org/redisson/codec/JsonJacksonCodec.java b/src/main/java/org/redisson/codec/JsonJacksonCodec.java index 815cede52f5a0a143de9a8f1bf2b11b8a4795616..9b5a271d35a914588d2dd6d48bc6593591b6f975 100755 --- a/src/main/java/org/redisson/codec/JsonJacksonCodec.java +++ b/src/main/java/org/redisson/codec/JsonJacksonCodec.java @@ -124,7 +124,8 @@ public class JsonJacksonCodec implements Codec { // warm up codec try { - mapObjectMapper.readValue("1".getBytes(), Object.class); + byte[] s = mapObjectMapper.writeValueAsBytes(1); + mapObjectMapper.readValue(s, Object.class); } catch (IOException e) { throw new IllegalStateException(e); } diff --git a/src/main/java/org/redisson/codec/SmileJacksonCodec.java b/src/main/java/org/redisson/codec/SmileJacksonCodec.java new file mode 100644 index 0000000000000000000000000000000000000000..7f8e84cd9bc89392e937ca1c4c2c832d7c2151f9 --- /dev/null +++ b/src/main/java/org/redisson/codec/SmileJacksonCodec.java @@ -0,0 +1,37 @@ +/** + * Copyright 2016 Nikita Koksharov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.redisson.codec; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.dataformat.smile.SmileFactory; + +/** + * Smile binary codec + * + * @author Nikita Koksharov + * + */ +public class SmileJacksonCodec extends JsonJacksonCodec { + + public SmileJacksonCodec() { + super(new ObjectMapper(new SmileFactory())); + } + + public SmileJacksonCodec(ClassLoader classLoader) { + super(createObjectMapper(classLoader, new ObjectMapper(new SmileFactory()))); + } + +} diff --git a/src/test/java/org/redisson/RedissonCodecTest.java b/src/test/java/org/redisson/RedissonCodecTest.java index 8f6d2574def32c451af43f57f344cf7631ee3b4c..bab1670ea624856ef45067c150f12aef836602dd 100644 --- a/src/test/java/org/redisson/RedissonCodecTest.java +++ b/src/test/java/org/redisson/RedissonCodecTest.java @@ -13,6 +13,7 @@ import org.redisson.codec.KryoCodec; import org.redisson.codec.LZ4Codec; import org.redisson.codec.MsgPackJacksonCodec; import org.redisson.codec.SerializationCodec; +import org.redisson.codec.SmileJacksonCodec; import org.redisson.codec.SnappyCodec; import org.redisson.config.Config; @@ -26,6 +27,8 @@ import java.util.Set; import static org.assertj.core.api.Assertions.assertThat; public class RedissonCodecTest extends BaseTest { + private Codec avroCodec = new SmileJacksonCodec(); + private Codec smileCodec = new SmileJacksonCodec(); private Codec codec = new SerializationCodec(); private Codec kryoCodec = new KryoCodec(); private Codec jsonCodec = new JsonJacksonCodec(); @@ -54,7 +57,7 @@ public class RedissonCodecTest extends BaseTest { test(); } - + @Test public void testMsgPack() { Config config = createConfig(); @@ -63,6 +66,24 @@ public class RedissonCodecTest extends BaseTest { test(); } + + @Test + public void testSmile() { + Config config = createConfig(); + config.setCodec(smileCodec); + redisson = Redisson.create(config); + + test(); + } + + @Test + public void testAvro() { + Config config = createConfig(); + config.setCodec(avroCodec); + redisson = Redisson.create(config); + + test(); + } @Test public void testFst() {