Package org.apache.avro.reflect
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
Nullableor aUnioncontainingVoid. - Arrays are mapped to Avro array schemas. If an array's
elements are a union defined by the
Unionannotation, 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"} Stringis 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,Fileare mapped to an Avro string schema asStringabletypes and serialized via theirtoStringmethod and de-serialized via theirStringconstructor. 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
genericAPI.
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.
-
ClassDescriptionAdds the given name and space as an alias to the schema.Specifies a default value for a field as a JSON string.Sets the avrodoc for this java field.Expert: Fields with this annotation are encoded using the given custom encoder.Marks a field as transient.Adds the given key:Value pair as metadata into the schema, at the corresponding node.Sets the avroname for this java field.Declares that a Java type should have a specified Avro schema, overriding the normally inferred schema.Expert: a custom encoder and decoder that writes an object directly to avro.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.MapEntryDeclares that null is a valid value for a Java type.Utilities to use existing Java classes and interfaces via reflection.ReflectDataimplementation that permits null field values.DatumReaderfor existing classes via Java reflection.DatumWriterfor existing classes via Java reflection.A few utility methods for using @link{java.misc.Unsafe}, mostly for private use.Declares that a class or field should be represented by an Avro string.Declares that a Java type should be represented by an Avro union schema.