com.adgear.anoa.write.AvroWriter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of anoa-core Show documentation
Show all versions of anoa-core Show documentation
Core classes for Anoa library, which aims to be a safe, convenient and fast record
de/serialization wrapper for the Avro, Thrift and Jackson libraries, using the functional idioms
of Java 8.
The anoa-core module tries to keep upstream dependencies to a minimum.
package com.adgear.anoa.write;
import com.fasterxml.jackson.core.JsonGenerator;
import org.apache.avro.Schema;
import org.apache.avro.generic.IndexedRecord;
import org.apache.avro.specific.SpecificData;
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Map;
class AvroWriter extends AbstractWriter {
final private LinkedHashMap> fieldMap;
AvroWriter(Class recordClass) {
this(SpecificData.get().getSchema(recordClass));
}
@SuppressWarnings("unchecked")
AvroWriter(Schema schema) {
fieldMap = new LinkedHashMap<>();
schema.getFields().stream()
.forEach(f -> fieldMap.put(f, (AbstractWriter