Last active
December 10, 2021 12:56
-
-
Save vepo/b1b84d1f3723ab1b867ebc02043c4912 to your computer and use it in GitHub Desktop.
Convert POJO/Map to AVRO GenericRecord
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.apache.avro.generic.GenericData; | |
import org.apache.avro.Schema; | |
import org.apache.avro.io.DecoderFactory; | |
import org.apache.avro.io.Decoder; | |
import org.apache.avro.io.DatumReader; | |
import org.apache.avro.generic.GenericDatumReader; | |
public class AvroConverter { | |
public static GenericData.Record parseJson(String data, Schema schema) throws IOException { | |
Decoder decoder = DecoderFactory.get().jsonDecoder(schema, data); | |
DatumReader<GenericData.Record> reader = new GenericDatumReader<>(schema); | |
return reader.read(null, decoder); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment