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 {@link
org.apache.avro.reflect.Nullable Nullable} or a {@link
org.apache.avro.reflect.Union Union} containing null.
- Arrays are mapped to Avro array schemas. If an array's
elements are a union defined by the {@link
org.apache.avro.reflect.Union 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"}
- {@link java.lang.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"}
- All other types are mapped as in the {@link org.apache.avro.generic
generic} API.
The {@link org.apache.avro.reflect.Union Union} annotation can be used
to support reflection of schemas for interfaces, abstract base classes
and other uses of polymorphism.
The {@link org.apache.avro.reflect.Stringable Stringable} annotation
will cause a type to be serialized via its {@link java.lang.Object#toString()
toString} method.