Search in sources :

Example 1 with AvroSchema

use of com.fasterxml.jackson.dataformat.avro.AvroSchema in project jvm-serializers by eishay.

the class JacksonAvroDatabind method register.

public static void register(TestGroups groups) {
    ObjectMapper mapper = new ObjectMapper(new AvroFactory());
    mapper.enable(SerializationFeature.WRITE_ENUMS_USING_INDEX);
    JavaType type = mapper.constructType(MediaContent.class);
    AvroSchema schema = new AvroSchema(Avro.Media.sMediaContent);
    ObjectReader reader = mapper.readerFor(type).with(schema);
    ObjectWriter writer = mapper.writerFor(type).with(schema);
    groups.media.add(JavaBuiltIn.mediaTransformer, new StdJacksonDataBind<MediaContent>("avro/jackson/databind", type, mapper, reader, writer), new SerFeatures(SerFormat.JSON, SerGraph.FLAT_TREE, SerClass.ZERO_KNOWLEDGE, ""));
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) AvroFactory(com.fasterxml.jackson.dataformat.avro.AvroFactory) AvroSchema(com.fasterxml.jackson.dataformat.avro.AvroSchema) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) MediaContent(data.media.MediaContent) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with AvroSchema

use of com.fasterxml.jackson.dataformat.avro.AvroSchema in project redisson by redisson.

the class RedissonCodecTest method testAvro.

@Test
public void testAvro() throws IOException {
    AvroMapper am = new AvroMapper();
    AvroSchema schema = am.schemaFor(TestObject.class);
    Codec avroCodec = new AvroJacksonCodec(TestObject.class, schema);
    Config config = createConfig();
    config.setCodec(avroCodec);
    RedissonClient redisson = Redisson.create(config);
    RBucket<TestObject> b = redisson.getBucket("bucket");
    b.set(new TestObject("1", "2"));
    assertThat(b.get()).isEqualTo(new TestObject("1", "2"));
}
Also used : Codec(org.redisson.client.codec.Codec) AvroSchema(com.fasterxml.jackson.dataformat.avro.AvroSchema) RedissonClient(org.redisson.api.RedissonClient) Config(org.redisson.config.Config) AvroMapper(com.fasterxml.jackson.dataformat.avro.AvroMapper) Test(org.junit.jupiter.api.Test)

Aggregations

AvroSchema (com.fasterxml.jackson.dataformat.avro.AvroSchema)2 JavaType (com.fasterxml.jackson.databind.JavaType)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectReader (com.fasterxml.jackson.databind.ObjectReader)1 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)1 AvroFactory (com.fasterxml.jackson.dataformat.avro.AvroFactory)1 AvroMapper (com.fasterxml.jackson.dataformat.avro.AvroMapper)1 MediaContent (data.media.MediaContent)1 Test (org.junit.jupiter.api.Test)1 RedissonClient (org.redisson.api.RedissonClient)1 Codec (org.redisson.client.codec.Codec)1 Config (org.redisson.config.Config)1