Package org.apache.avro

Examples of org.apache.avro.FooBarSpecificRecord


    Builder newBuilder = FooBarSpecificRecord.newBuilder();
    newBuilder.setId(42);
    newBuilder.setName("foo");
    newBuilder.setNicknames(Arrays.asList("bar"));
    newBuilder.setRelatedids(Arrays.asList(1,2,3));
    FooBarSpecificRecord specificRecord = newBuilder.build();
   
    byte[] recordBytes = serializeRecord(specificRecord);
   
    Decoder decoder = DecoderFactory.get().binaryDecoder(recordBytes, null);
    SpecificDatumReader<FooBarSpecificRecord> specificDatumReader = new SpecificDatumReader<FooBarSpecificRecord>(FooBarSpecificRecord.SCHEMA$);
    FooBarSpecificRecord deserialized = new FooBarSpecificRecord();
    specificDatumReader.read(deserialized, decoder);
   
    assertEquals(specificRecord, deserialized);
  }
View Full Code Here


    Assert.assertEquals(Kind.getClassSchema(), Kind.SCHEMA$);
  }

  @Test
  public void testSpecificRecordToString() throws IOException {
    FooBarSpecificRecord foo = FooBarSpecificRecord.newBuilder()
      .setId(123)
      .setName("foo")
      .setNicknames(Arrays.asList("bar"))
      .setRelatedids(Arrays.asList(1, 2, 3))
      .setTypeEnum(TypeEnum.c)
      .build();

    String json = foo.toString();
    JsonFactory factory = new JsonFactory();
    JsonParser parser = factory.createJsonParser(json);
    ObjectMapper mapper = new ObjectMapper();

    // will throw exception if string is not parsable json
View Full Code Here

  @Test
  public void testRead() throws IOException {
    Builder newBuilder = FooBarSpecificRecord.newBuilder();
    newBuilder.setId(42);
    newBuilder.setRelatedids(Arrays.asList(1,2,3));
    FooBarSpecificRecord specificRecord = newBuilder.build();
   
    byte[] recordBytes = serializeRecord(specificRecord);
   
    Decoder decoder = DecoderFactory.get().binaryDecoder(recordBytes, null);
    SpecificDatumReader<FooBarSpecificRecord> specificDatumReader = new SpecificDatumReader<FooBarSpecificRecord>(FooBarSpecificRecord.SCHEMA$);
    FooBarSpecificRecord deserialized = new FooBarSpecificRecord();
    specificDatumReader.read(deserialized, decoder);
   
    assertEquals(specificRecord, deserialized);
       
  }
View Full Code Here

public class TestReflectDatumReader {

  @Test
  public void testRead_SpecificDataRecord() throws IOException {
    FooBarSpecificRecord specificRecord = FooBarSpecificRecord.newBuilder().setId(42)
        .setRelatedids(Arrays.asList(1, 2, 3)).build();
    byte[] specificRecordBytes = TestSpecificDatumReader.serializeRecord(specificRecord);

    Decoder decoder = DecoderFactory.get().binaryDecoder(specificRecordBytes, null);
    ReflectDatumReader<FooBarSpecificRecord> reflectDatumReader = new ReflectDatumReader<FooBarSpecificRecord>(
        FooBarSpecificRecord.class);

    FooBarSpecificRecord deserialized = new FooBarSpecificRecord();
    reflectDatumReader.read(deserialized, decoder);

    assertEquals(specificRecord, deserialized);
  }
View Full Code Here

    Assert.assertEquals(Kind.getClassSchema(), Kind.SCHEMA$);
  }

  @Test
  public void testSpecificRecordToString() throws IOException {
    FooBarSpecificRecord foo = FooBarSpecificRecord.newBuilder()
      .setId(123)
      .setName("foo")
      .setNicknames(Arrays.asList("bar"))
      .setRelatedids(Arrays.asList(1, 2, 3))
      .setTypeEnum(TypeEnum.c)
      .build();

    String json = foo.toString();
    JsonFactory factory = new JsonFactory();
    JsonParser parser = factory.createJsonParser(json);
    ObjectMapper mapper = new ObjectMapper();

    // will throw exception if string is not parsable json
View Full Code Here

    Reflection.class.getMethod("primitive", integerClass);
  }

  @Test
  public void testToString() throws IOException {
   FooBarSpecificRecord foo = FooBarSpecificRecord.newBuilder()
           .setId(123)
           .setRelatedids(Arrays.asList(1,2,3))
           .setTypeEnum(TypeEnum.c)
           .build();
   
    String json = foo.toString();
    JsonFactory factory = new JsonFactory();
    JsonParser parser = factory.createJsonParser(json);
    ObjectMapper mapper = new ObjectMapper();
   
    // will throw exception if string is not parsable json
View Full Code Here

TOP

Related Classes of org.apache.avro.FooBarSpecificRecord

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.