Package org.apache.avro.hadoop.io

# Class AvroSerializer<T>

java.lang.Object
org.apache.avro.hadoop.io.AvroSerializer<T>

Type Parameters:
  `T` - The Java type of the Avro data.

All Implemented Interfaces:
  `Serializer<AvroWrapper<T>>`

public class AvroSerializer<T> extends Object implements Serializer<AvroWrapper<T>>
Serializes AvroWrapper objects within Hadoop.

Keys and values containing Avro types are more efficiently serialized outside of the WritableSerialization model, so they are wrapped in `AvroWrapper` objects and serialization is handled by this class.

MapReduce jobs that use AvroWrapper objects as keys or values need to be configured with `AvroSerialization`. Use `AvroJob` to help with Job configuration.

## Constructor Summary

Constructors
Constructor
Description
`AvroSerializer(org.apache.avro.Schema writerSchema)`
Constructor.
`AvroSerializer(org.apache.avro.Schema writerSchema, org.apache.avro.io.DatumWriter<T> datumWriter)`
Constructor.

## Method Summary

Modifier and Type
Method
Description
`void`
`close()`
`org.apache.avro.Schema`
`getWriterSchema()`
Gets the writer schema being used for serialization.
`void`
`open(OutputStream outputStream)`
`void`
`serialize(AvroWrapper<T> avroWrapper)`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### AvroSerializer

public AvroSerializer(org.apache.avro.Schema writerSchema)
Constructor.

Parameters:
  `writerSchema` - The writer schema for the Avro data being serialized.

### AvroSerializer

public AvroSerializer(org.apache.avro.Schema writerSchema, org.apache.avro.io.DatumWriter<T> datumWriter)
Constructor.

Parameters:
  `writerSchema` - The writer schema for the Avro data being serialized.
  `datumWriter` - The datum writer to use for serialization.

## Method Details

### getWriterSchema

public org.apache.avro.Schema getWriterSchema()
Gets the writer schema being used for serialization.

Returns:
  The writer schema.

### open

public void open(OutputStream outputStream) throws IOException

Specified by:
  `open` in interface `Serializer<T>`
Throws:
  `IOException`

### serialize

public void serialize(AvroWrapper<T> avroWrapper) throws IOException

Specified by:
  `serialize` in interface `Serializer<T>`
Throws:
  `IOException`

### close

public void close() throws IOException

Specified by:
  `close` in interface `Serializer<T>`
Throws:
  `IOException`