Class SpecificData

java.lang.Object
org.apache.avro.generic.GenericData
org.apache.avro.specific.SpecificData
Direct Known Subclasses:
ReflectData

public class SpecificData extends GenericData
Utilities for generated Java classes and interfaces.
  • Field Details

    • CLASS_PROP

      public static final String CLASS_PROP
      See Also:
    • KEY_CLASS_PROP

      public static final String KEY_CLASS_PROP
      See Also:
    • ELEMENT_PROP

      public static final String ELEMENT_PROP
      See Also:
    • RESERVED_WORD_ESCAPE_CHAR

      public static final char RESERVED_WORD_ESCAPE_CHAR
      See Also:
    • RESERVED_WORDS

      public static final Set<String> RESERVED_WORDS
      Reserved words from https://docs.oracle.com/javase/specs/jls/se16/html/jls-3.html require mangling in order to be used in generated Java code.
    • ACCESSOR_MUTATOR_RESERVED_WORDS

      public static final Set<String> ACCESSOR_MUTATOR_RESERVED_WORDS
    • TYPE_IDENTIFIER_RESERVED_WORDS

      public static final Set<String> TYPE_IDENTIFIER_RESERVED_WORDS
    • ERROR_RESERVED_WORDS

      public static final Set<String> ERROR_RESERVED_WORDS
    • stringableClasses

      protected Set<Class> stringableClasses
      Read/write some common builtin classes as strings. Representing these as strings isn't always best, as they aren't always ordered ideally, but at least they're stored. Also note that, for compatibility, only classes that wouldn't be otherwise correctly readable or writable should be added here, e.g., those without a no-arg constructor or those whose fields are all transient.
  • Constructor Details

    • SpecificData

      public SpecificData()
      For subclasses. Applications normally use get().
    • SpecificData

      public SpecificData(ClassLoader classLoader)
      Construct with a specific classloader.
  • Method Details

    • createDatumReader

      public DatumReader createDatumReader(Schema schema)
      Description copied from class: GenericData
      Returns a DatumReader for this kind of data.
      Overrides:
      createDatumReader in class GenericData
    • createDatumReader

      public DatumReader createDatumReader(Schema writer, Schema reader)
      Description copied from class: GenericData
      Returns a DatumReader for this kind of data.
      Overrides:
      createDatumReader in class GenericData
    • createDatumWriter

      public DatumWriter createDatumWriter(Schema schema)
      Description copied from class: GenericData
      Returns a DatumWriter for this kind of data.
      Overrides:
      createDatumWriter in class GenericData
    • get

      public static SpecificData get()
      Return the singleton instance.
    • getForSchema

      public static SpecificData getForSchema(Schema reader)
      For RECORD and UNION type schemas, this method returns the SpecificData instance of the class associated with the schema, in order to get the right conversions for any logical types used.
      Parameters:
      reader - the reader schema
      Returns:
      the SpecificData associated with the schema's class, or the default instance.
    • getForClass

      public static <T> SpecificData getForClass(Class<T> c)
      If the given class is assignable to SpecificRecordBase, this method returns the SpecificData instance from the field MODEL$, in order to get the correct Conversion instances for the class. Falls back to the default instance get() for other classes or if the field is not found.
      Type Parameters:
      T - .
      Parameters:
      c - A class
      Returns:
      The SpecificData from the SpecificRecordBase instance, or the default SpecificData instance.
    • useCustomCoders

      public boolean useCustomCoders()
      Retrieve the current value of the custom-coders feature flag. Defaults to false, but this default can be overridden using the system property org.apache.avro.specific.use_custom_coders, and can be set dynamically by useCustomCoders(). See invalid input: '<'a href="https://avro.apache.org/docs/current/gettingstartedjava.html#Beta+feature:+Generating+faster+code"Getting started with Java for more about this feature flag.
    • setCustomCoders

      public void setCustomCoders(boolean flag)
      Dynamically set the value of the custom-coder feature flag. See useCustomCoders().
    • isEnum

      protected boolean isEnum(Object datum)
      Description copied from class: GenericData
      Overrides:
      isEnum in class GenericData
    • createEnum

      public Object createEnum(String symbol, Schema schema)
      Description copied from class: GenericData
      Called to create an enum value. May be overridden for alternate enum representations. By default, returns a GenericEnumSymbol.
      Overrides:
      createEnum in class GenericData
    • getEnumSchema

      protected Schema getEnumSchema(Object datum)
      Description copied from class: GenericData
      Called to obtain the schema of a enum. By default calls {GenericContainer#getSchema(). May be overridden for alternate enum representations.
      Overrides:
      getEnumSchema in class GenericData
    • mangleFullyQualified

      public static String mangleFullyQualified(String fullName)
      Utility to mangle the fully qualified class name into a valid symbol.
    • mangle

      public static String mangle(String word)
      Utility for template use. Adds a dollar sign to reserved words.
    • mangle

      public static String mangle(String word, boolean isError)
      Utility for template use. Adds a dollar sign to reserved words.
    • mangleTypeIdentifier

      public static String mangleTypeIdentifier(String word)
      Utility for template use. Adds a dollar sign to reserved words in type identifiers.
    • mangleTypeIdentifier

      public static String mangleTypeIdentifier(String word, boolean isError)
      Utility for template use. Adds a dollar sign to reserved words in type identifiers.
    • mangle

      public static String mangle(String word, Set<String> reservedWords)
      Utility for template use. Adds a dollar sign to reserved words.
    • mangleMethod

      public static String mangleMethod(String word, boolean isError)
    • mangle

      public static String mangle(String word, Set<String> reservedWords, boolean isMethod)
      Utility for template use. Adds a dollar sign to reserved words.
    • unmangle

      protected static String unmangle(String word)
      Undoes mangling for reserved words.
    • getClass

      public Class getClass(Schema schema)
      Return the class that implements a schema, or null if none exists.
    • getClassName

      public static String getClassName(Schema schema)
      Returns the Java class name indicated by a schema's name and namespace.
    • getSchema

      public Schema getSchema(Type type)
      Find the schema for a Java type.
    • createSchema

      protected Schema createSchema(Type type, Map<String,Schema> names)
      Create the schema for a Java type.
    • getSchemaName

      protected String getSchemaName(Object datum)
      Description copied from class: GenericData
      Return the schema full name for a datum. Called by GenericData.resolveUnion(Schema,Object).
      Overrides:
      getSchemaName in class GenericData
    • isStringable

      protected boolean isStringable(Class<?> c)
      True if a class should be serialized with toString().
    • isStringType

      protected boolean isStringType(Class<?> c)
      True if a class IS a string type
    • getProtocol

      public Protocol getProtocol(Class iface)
      Return the protocol for a Java interface.
    • compare

      protected int compare(Object o1, Object o2, Schema s, boolean eq)
      Description copied from class: GenericData
      Comparison implementation. When equals is true, only checks for equality, not for order.
      Overrides:
      compare in class GenericData
    • newInstance

      public static Object newInstance(Class c, Schema s)
      Create an instance of a class. If the class implements SpecificData.SchemaConstructable, call a constructor with a Schema parameter, otherwise use a no-arg constructor.
    • createFixed

      public Object createFixed(Object old, Schema schema)
      Description copied from class: GenericData
      Called to create an fixed value. May be overridden for alternate fixed representations. By default, returns GenericFixed.
      Overrides:
      createFixed in class GenericData
    • newRecord

      public Object newRecord(Object old, Schema schema)
      Description copied from class: GenericData
      Called to create new record instances. Subclasses may override to use a different record implementation. The returned instance must conform to the schema provided. If the old object contains fields not present in the schema, they should either be removed from the old object, or it should create a new instance that conforms to the schema. By default, this returns a GenericData.Record.
      Overrides:
      newRecord in class GenericData
    • getNewRecordSupplier

      public GenericData.InstanceSupplier getNewRecordSupplier(Schema schema)
      Description copied from class: GenericData
      create a supplier that allows to get new record instances for a given schema in an optimized way
      Overrides:
      getNewRecordSupplier in class GenericData
    • getDecoder

      public static BinaryDecoder getDecoder(ObjectInput in)
      Runtime utility used by generated classes.
    • getEncoder

      public static BinaryEncoder getEncoder(ObjectOutput out)
      Runtime utility used by generated classes.
    • createString

      public Object createString(Object value)
      Description copied from class: GenericData
      Called to create an string value. May be overridden for alternate string representations.
      Overrides:
      createString in class GenericData