# Package org.apache.avro.reflect

package org.apache.avro.reflect
Use Java reflection to generate schemas and protocols for existing classes.

Java types are mapped to Avro schemas as follows:

- Classes are mapped to Avro records. Only concrete classes with a no-argument constructor are supported. All inherited fields that are not static or transient are used. Fields are not permitted to be null unless annotated by `Nullable` or a `Union` containing `Void`.
- Arrays are mapped to Avro array schemas. If an array's elements are a union defined by the `Union` annotation, the "java-element" property is set to the union's class, e.g.:

      {"type": "array", "java-element": "org.acme.Foo"}

- Collection implementations are mapped to Avro array schemas with the "java-class" property set to the collection implementation, e.g.:

      {"type": "array", "java-class": "java.util.ArrayList"}

- `String` is mapped to an Avro string schema.
- byte[] is mapped to an Avro bytes schema.
- short is mapped to an Avro int schema with the "java-class" property set to "java.lang.Short", e.g.:

      {"type": "int", "java-class": "java.lang.Short"}

- `BigDecimal`, `BigInteger`, `URI`, `URL`, `File` are mapped to an Avro string schema as `Stringable` types and serialized via their `toString` method and de-serialized via their `String` constructor. This is done via the "java-class", "java-key-class" or "java-element-class" depending on whether it is a field, or map key or a list/map element, e.g.:

      {"type": "string", "java-class": "java.math.BigDecimal"}

- All other types are mapped as in the `generic` API.

The `Union` annotation can be used to support reflection of schemas for interfaces, abstract base classes and other uses of polymorphism.

The `Stringable` annotation will cause a type to be serialized via its `toString` method.

Fields annotated with `AvroIgnore` will not be written or read to.

The `AvroName` annotation renames the field in the schema to the given name. The reflect datum reader will look for a schema field with the given name, when trying to read into such an annotated java field.

The `AvroMeta` annotation adds an arbitrary key:value pair in the schema at the node of the java field.

The `AvroSchema` annotation forces the use of an custom schema.

The `AvroEncode` annotation forces the use of an custom encoder. This annotation overrides `Stringable` and `Nullable`.

Related Packages
Package
Description
org.apache.avro
Avro kernel classes.
Class
Description
AvroAlias
Adds the given name and space as an alias to the schema.
AvroAliases
AvroDefault
Specifies a default value for a field as a JSON string.
AvroDoc
Sets the avrodoc for this java field.
AvroEncode
Expert: Fields with this annotation are encoded using the given custom encoder.
AvroIgnore
Marks a field as transient.
AvroMeta
Adds the given key:Value pair as metadata into the schema, at the corresponding node.
AvroMeta.AvroMetas
AvroName
Sets the avroname for this java field.
AvroSchema
Declares that a Java type should have a specified Avro schema, overriding the normally inferred schema.
CustomEncoding<T>
Expert: a custom encoder and decoder that writes an object directly to avro.
DateAsLongEncoding
This encoder/decoder writes a java.util.Date object as a long to avro and reads a Date object from long.
MapEntry<K,V>
Deprecated.
Use org.apache.avro.util.MapEntry
Nullable
Declares that null is a valid value for a Java type.
ReflectData
Utilities to use existing Java classes and interfaces via reflection.
ReflectData.AllowNull
`ReflectData` implementation that permits null field values.
ReflectDatumReader<T>
`DatumReader` for existing classes via Java reflection.
ReflectDatumWriter<T>
`DatumWriter` for existing classes via Java reflection.
ReflectionUtil
A few utility methods for using @link{java.misc.Unsafe}, mostly for private use.
Stringable
Declares that a class or field should be represented by an Avro string.
Union
Declares that a Java type should be represented by an Avro union schema.