All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.fasterxml.jackson.dataformat.avro.AvroModule Maven / Gradle / Ivy

There is a newer version: 2.18.2
Show newest version
package com.fasterxml.jackson.dataformat.avro;

import java.io.IOException;

import org.apache.avro.Schema;

import com.fasterxml.jackson.core.*;

import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;

/**
 * Module that adds support for handling datatypes specific to the standard
 * Java Avro library; most specifically {@link Schema}
 *
 * @since 2.5
 */
public class AvroModule extends SimpleModule
{
    private static final long serialVersionUID = 1L;

    public AvroModule()
    {
        super(PackageVersion.VERSION);
        addSerializer(new SchemaSerializer());
    }

    public Schema schema;

    /*
    /**********************************************************
    /* Helper classes (as long as number is small)
    /**********************************************************
     */

    public static class SchemaSerializer extends StdSerializer
    {
        private static final long serialVersionUID = 1L;

        public SchemaSerializer() {
            super(Schema.class);
        }

        @Override
        public void serialize(Schema value, JsonGenerator gen, SerializerProvider prov)
                throws IOException {
            // Let's simply write as String, for now
            gen.writeString(value.toString());
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy