com.fasterxml.jackson.dataformat.avro.AvroModule Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jackson-dataformat-avro Show documentation
Show all versions of jackson-dataformat-avro Show documentation
Support for reading and writing AVRO-encoded data via Jackson
abstractions.
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