org.apache.avro.reflect

## Class ReflectDatumReader<T>

- java.lang.Object
- - org.apache.avro.generic.GenericDatumReader<T>
  - - org.apache.avro.specific.SpecificDatumReader<T>
    - - org.apache.avro.reflect.ReflectDatumReader<T>

- All Implemented Interfaces:
    DatumReader<T>

      public class ReflectDatumReader<T>
      extends SpecificDatumReader<T>

  `DatumReader` for existing classes via Java reflection.

- - ### Field Summary

    - ### Fields inherited from class org.apache.avro.specific.SpecificDatumReader

      `SERIALIZABLE_PACKAGES`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ReflectDatumReader()`
    `ReflectDatumReader(Class<T> c)` Construct for reading instances of a class.
    `ReflectDatumReader(ReflectData data)` Construct given a `ReflectData`.
    `ReflectDatumReader(Schema root)` Construct where the writer's and reader's schemas are the same.
    `ReflectDatumReader(Schema writer, Schema reader)` Construct given writer's and reader's schema.
    `ReflectDatumReader(Schema writer, Schema reader, ReflectData data)` Construct given writer's and reader's schema and the data model.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `addToArray(Object array, long pos, Object e)` Called by the default implementation of `GenericDatumReader.readArray(java.lang.Object, org.apache.avro.Schema, org.apache.avro.io.ResolvingDecoder)` to add a value.
    `protected Object` | `createString(String value)` Called to create a string from a default value.
    `protected Object` | `newArray(Object old, int size, Schema schema)` Called to create new array instances.
    `protected Object` | `peekArray(Object array)` Called by the default implementation of `GenericDatumReader.readArray(java.lang.Object, org.apache.avro.Schema, org.apache.avro.io.ResolvingDecoder)` to retrieve a value from a reused instance.
    `protected Object` | `readArray(Object old, Schema expected, ResolvingDecoder in)` Called to read an array instance.
    `protected Object` | `readBytes(Object old, Schema s, Decoder in)` Called to read byte arrays.
    `protected void` | `readField(Object record, Schema.Field field, Object oldDatum, ResolvingDecoder in, Object state)` Called to read a single field of a record.
    `protected Object` | `readInt(Object old, Schema expected, Decoder in)` Called to read integers.
    `protected Object` | `readString(Object old, Decoder in)` Called to read strings.

    - ### Methods inherited from class org.apache.avro.specific.SpecificDatumReader

      `findStringClass, getSpecificData, getTrustedPackages, readRecord, setSchema`

    - ### Methods inherited from class org.apache.avro.generic.GenericDatumReader

      `addToMap, convert, createBytes, createEnum, createFixed, createFixed, getData, getExpected, getResolver, getSchema, newInstanceFromString, newMap, newRecord, read, read, readBytes, readEnum, readFixed, readMap, readMapKey, readString, readWithConversion, readWithoutConversion, setExpected, skip`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### ReflectDatumReader

          public ReflectDatumReader()

    - #### ReflectDatumReader

          public ReflectDatumReader(Class<T> c)

      Construct for reading instances of a class.

    - #### ReflectDatumReader

          public ReflectDatumReader(Schema root)

      Construct where the writer's and reader's schemas are the same.

    - #### ReflectDatumReader

          public ReflectDatumReader(Schema writer,
                                    Schema reader)

      Construct given writer's and reader's schema.

    - #### ReflectDatumReader

          public ReflectDatumReader(Schema writer,
                                    Schema reader,
                                    ReflectData data)

      Construct given writer's and reader's schema and the data model.

    - #### ReflectDatumReader

          public ReflectDatumReader(ReflectData data)

      Construct given a `ReflectData`.

  - ### Method Detail

    - #### newArray

          protected Object newArray(Object old,
                                    int size,
                                    Schema schema)

      Description copied from class: `GenericDatumReader`
      Called to create new array instances. Subclasses may override to use a different array implementation. By default, this returns a `GenericData.Array`.
      Overrides:
        `newArray` in class `GenericDatumReader<T>`

    - #### peekArray

          protected Object peekArray(Object array)

      Description copied from class: `GenericDatumReader`
      Called by the default implementation of `GenericDatumReader.readArray(java.lang.Object, org.apache.avro.Schema, org.apache.avro.io.ResolvingDecoder)` to retrieve a value from a reused instance. The default implementation is for `GenericArray`.
      Overrides:
        `peekArray` in class `GenericDatumReader<T>`

    - #### addToArray

          protected void addToArray(Object array,
                                    long pos,
                                    Object e)

      Description copied from class: `GenericDatumReader`
      Called by the default implementation of `GenericDatumReader.readArray(java.lang.Object, org.apache.avro.Schema, org.apache.avro.io.ResolvingDecoder)` to add a value. The default implementation is for `Collection`.
      Overrides:
        `addToArray` in class `GenericDatumReader<T>`

    - #### readArray

          protected Object readArray(Object old,
                                     Schema expected,
                                     ResolvingDecoder in)
                              throws IOException

      Description copied from class: `GenericDatumReader`
      Called to read an array instance. May be overridden for alternate array representations.
      Overrides:
        `readArray` in class `GenericDatumReader<T>`
      Throws:
        `IOException`

    - #### readString

          protected Object readString(Object old,
                                      Decoder in)
                               throws IOException

      Description copied from class: `GenericDatumReader`
      Called to read strings. Subclasses may override to use a different string representation. By default, this calls `Decoder.readString(Utf8)`.
      Overrides:
        `readString` in class `GenericDatumReader<T>`
      Throws:
        `IOException`

    - #### createString

          protected Object createString(String value)

      Description copied from class: `GenericDatumReader`
      Called to create a string from a default value. Subclasses may override to use a different string representation. By default, this calls `Utf8(String)`.
      Overrides:
        `createString` in class `GenericDatumReader<T>`

    - #### readBytes

          protected Object readBytes(Object old,
                                     Schema s,
                                     Decoder in)
                              throws IOException

      Description copied from class: `GenericDatumReader`
      Called to read byte arrays. Subclasses may override to use a different byte array representation. By default, this calls `Decoder.readBytes(ByteBuffer)`.
      Overrides:
        `readBytes` in class `GenericDatumReader<T>`
      Throws:
        `IOException`

    - #### readInt

          protected Object readInt(Object old,
                                   Schema expected,
                                   Decoder in)
                            throws IOException

      Description copied from class: `GenericDatumReader`
      Called to read integers. Subclasses may override to use a different integer representation. By default, this calls `Decoder.readInt()`.
      Overrides:
        `readInt` in class `GenericDatumReader<T>`
      Throws:
        `IOException`

    - #### readField

          protected void readField(Object record,
                                   Schema.Field field,
                                   Object oldDatum,
                                   ResolvingDecoder in,
                                   Object state)
                            throws IOException

      Description copied from class: `GenericDatumReader`
      Called to read a single field of a record. May be overridden for more efficient or alternate implementations.
      Overrides:
        `readField` in class `SpecificDatumReader<T>`
      Throws:
        `IOException`

Copyright © 2009–2024 The Apache Software Foundation. All rights reserved.