Last active
July 18, 2016 16:06
-
-
Save cykl/bf8936fca0410d0cea61402bf5b1e5f9 to your computer and use it in GitHub Desktop.
Does Avro Reflect need a public no-arg ctor ?
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 java.io.File; | |
import java.io.IOException; | |
import org.apache.avro.file.DataFileReader; | |
import org.apache.avro.file.DataFileWriter; | |
import org.apache.avro.io.DatumReader; | |
import org.apache.avro.io.DatumWriter; | |
import org.apache.avro.reflect.ReflectData; | |
import org.apache.avro.reflect.ReflectDatumReader; | |
import org.apache.avro.reflect.ReflectDatumWriter; | |
import org.assertj.core.api.WithAssertions; | |
import org.junit.Rule; | |
import org.junit.Test; | |
import org.junit.rules.TemporaryFolder; | |
public class AvroReflectVsPrivateCtorTest implements WithAssertions { | |
@Rule | |
public TemporaryFolder tmpFolder = new TemporaryFolder(); | |
@Test | |
public void should_ctor_be_public() throws IOException { | |
File file = new File(tmpFolder.getRoot(), "avro"); | |
DatumWriter<Pojo> datumWriter = new ReflectDatumWriter<>(Pojo.class); | |
try (DataFileWriter<Pojo> writer = new DataFileWriter<>(datumWriter)) { | |
writer.create(ReflectData.get().getSchema(Pojo.class), file); | |
writer.append(new Pojo("John")); | |
} | |
DatumReader<Pojo> datumReader = new ReflectDatumReader<>(Pojo.class); | |
try (DataFileReader<Pojo> reader = new DataFileReader<>(file, datumReader)) { | |
Pojo pojo = reader.next(); | |
assertThat(pojo.getName()).isEqualTo("John"); | |
} | |
} | |
} |
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
public class Pojo { | |
private String name; | |
private Pojo() { | |
// Mandatory no-arg ctor | |
} | |
public Pojo(String name) { | |
this.name = name; | |
} | |
public String getName() { | |
return name; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment