Java Code Examples for org.apache.avro.specific.SpecificRecord#getSchema()

The following examples show how to use org.apache.avro.specific.SpecificRecord#getSchema() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WatcherAvroUtil.java    From reef with Apache License 2.0 5 votes vote down vote up
public static String toString(final SpecificRecord record) {
  final String jsonEncodedRecord;
  try {
    final Schema schema = record.getSchema();
    final ByteArrayOutputStream bos = new ByteArrayOutputStream();
    final Encoder encoder = EncoderFactory.get().jsonEncoder(schema, bos);
    final SpecificDatumWriter datumWriter = new SpecificDatumWriter(record.getClass());
    datumWriter.write(record, encoder);
    encoder.flush();
    jsonEncodedRecord = new String(bos.toByteArray(), Charset.forName("UTF-8"));
  } catch (final IOException e) {
    throw new RuntimeException(e);
  }
  return jsonEncodedRecord;
}
 
Example 2
Source File: AvroSpecificSerialization.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@InterfaceAudience.Private
@Override
public Schema getSchema(SpecificRecord t) {
  return t.getSchema();
}
 
Example 3
Source File: AvroSpecificSerialization.java    From big-c with Apache License 2.0 4 votes vote down vote up
@InterfaceAudience.Private
@Override
public Schema getSchema(SpecificRecord t) {
  return t.getSchema();
}