org.apache.avro.reflect.package.html Maven / Gradle / Ivy
Show all versions of hive-apache Show documentation
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 {@link java.lang.Void}.
- 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"}
- {@link java.math.BigDecimal}, {@link java.math.BigInteger},
{@link java.net.URI}, {@link java.net.URL}, {@link java.io.File}
are mapped to an Avro string schema as
{@link org.apache.avro.reflect.Stringable Stringable} types and
serialized via their {@link java.lang.Object#toString() toString}
method and de-serialized via their {@link java.lang.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 {@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.
Fields annotated with {@link org.apache.avro.reflect.AvroIgnore AvroIgnore}
will not be written or read to.
The {@link org.apache.avro.reflect.AvroName 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 {@link org.apache.avro.reflect.AvroMeta AvroMeta} annotation adds an
arbitrary key:value pair in the schema at the node of the java field.
The {@link org.apache.avro.reflect.AvroSchema AvroSchema} annotation forces
the use of an custom schema.
The {@link org.apache.avro.reflect.AvroEncode AvroEncode} annotation forces
the use of an custom encoder. This annotation overrides
{@link org.apache.avro.reflect.Stringable Stringable} and
{@link org.apache.avro.reflect.Nullable Nullable}.