Method Create
Create(AvroSchema, GenericDatumReaderOptions?)
Gets the reader for schema, compiling it on first use. Readers with the default options are
cached per schema; readers with custom options are created each time, so keep and reuse them.
public static GenericDatumReader Create(AvroSchema schema, GenericDatumReaderOptions? options = null)
Parameters
schemaAvroSchemaThe schema the data was written with.
optionsGenericDatumReaderOptions
Returns
Create(AvroSchema, AvroSchema, GenericDatumReaderOptions?)
Gets a reader for data written with writerSchema that returns values of
readerSchema, resolving the differences the specification allows:
- record fields are matched by name or by the reader field's aliases; writer fields the reader does not have are skipped, and reader fields the writer does not have take their default value;
- named types match by full name, unqualified name, or the reader's aliases;
- numbers are promoted (
inttolong,floatordouble;longtofloatordouble;floattodouble), andstringandbytesconvert to each other; - enum symbols are matched by name, and a symbol the reader lacks takes the reader's enum default;
- a writer union reads each branch as the reader schema (or the first matching branch of a reader union), and a non-union writer schema is read as the first matching branch of a reader union.
public static GenericDatumReader Create(AvroSchema writerSchema, AvroSchema readerSchema, GenericDatumReaderOptions? options = null)
Parameters
writerSchemaAvroSchemaThe schema the data was written with.
readerSchemaAvroSchemaThe schema to read the data as.
optionsGenericDatumReaderOptions
Returns
Remarks
Logical types don't take part, as in Java: values are read as the reader's logical type, so a decimal of another scale reads as another number (the specification says such decimals don't match). Check(AvroSchema, AvroSchema, AvroCompatibilityOptions?) warns about it. Readers with the default options are cached per pair of schemas. A mismatch that the data may never contain (a union branch with no counterpart, an enum symbol without a default) is reported with AvroDataException only when such a value is read, as in the Java implementation.
Exceptions
- AvroSchemaException
The schemas cannot be resolved (for example a reader field without a default that the writer lacks).