Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use a super class in convert json instead of generic #47

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package tech.allegro.schema.json2avro.converter;

import org.apache.avro.Schema;
import org.apache.avro.generic.GenericData;
import org.apache.avro.generic.GenericDatumReader;
import org.apache.avro.generic.GenericDatumWriter;
import org.apache.avro.generic.GenericRecord;
import org.apache.avro.generic.*;
import org.apache.avro.io.BinaryDecoder;
import org.apache.avro.io.BinaryEncoder;
import org.apache.avro.io.DatumWriter;
Expand Down Expand Up @@ -89,11 +86,11 @@ public byte[] convertToJson(byte[] avro, Schema schema) {
}
}

public byte[] convertToJson(GenericRecord record) {
public byte[] convertToJson(IndexedRecord record) {
try {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
NoWrappingJsonEncoder jsonEncoder = new NoWrappingJsonEncoder(record.getSchema(), outputStream);
DatumWriter<GenericRecord> writer = record instanceof SpecificRecord ?
DatumWriter<IndexedRecord> writer = record instanceof SpecificRecord ?
new SpecificDatumWriter<>(record.getSchema()) :
new GenericDatumWriter<>(record.getSchema());
writer.write(record, jsonEncoder);
Expand Down