java.lang.Object
tools.jackson.dataformat.avro.schema.AvroSchemaHelper

public abstract class AvroSchemaHelper extends Object
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Constant used by native Avro Schemas for indicating more specific physical class of a value; referenced indirectly to reduce direct dependencies to the standard avro library.
    static final String
    Constant used by native Avro Schemas for indicating more specific physical class of a array element; referenced indirectly to reduce direct dependencies to the standard avro library.
    static final String
    Constant used by native Avro Schemas for indicating more specific physical class of a map key; referenced indirectly to reduce direct dependencies to the standard avro library.
    protected static final Set<Class<?>>
    Default stringable classes
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static org.apache.avro.Schema
    addAlias(org.apache.avro.Schema schema, tools.jackson.databind.introspect.AnnotatedClass annotations)
    Looks for @AvroAlias on bean and adds it to schema if it exists
    static org.apache.avro.Schema
     
    static org.apache.avro.Schema
    createEnumSchema(tools.jackson.databind.cfg.MapperConfig<?> config, tools.jackson.databind.JavaType enumType, tools.jackson.databind.introspect.AnnotatedClass annotations, List<String> values)
    Constructs a new enum schema
    static org.apache.avro.Schema
    Helper method to enclose details of expressing best Avro Schema for UUID: 16-byte fixed-length binary (alternative would be basic variable length "bytes").
    static String
    getFullName(org.apache.avro.Schema schema)
    Returns the full name of a schema; This is similar to Schema.getFullName(), except that it properly handles namespaces for nested classes
    protected static String
     
    protected static String
    getNamespace(tools.jackson.databind.JavaType type, tools.jackson.databind.introspect.AnnotatedClass annotations)
     
    static String
    getTypeId(Class<?> type)
    Returns the Avro type ID for a given type
    static String
    getTypeId(org.apache.avro.Schema schema)
    Returns the type ID for this schema, or null if none is present.
    static String
    getTypeId(tools.jackson.databind.JavaType type)
     
    protected static String
    getTypeName(tools.jackson.databind.JavaType type)
     
    static org.apache.avro.Schema
    initializeRecordSchema(tools.jackson.databind.cfg.MapperConfig<?> config, tools.jackson.databind.JavaType type, tools.jackson.databind.introspect.AnnotatedClass annotations)
    Initializes a record schema with metadata from the given class; this schema is returned in a non-finalized state, and still needs to have fields added to it.
    static boolean
    isStringable(tools.jackson.databind.introspect.AnnotatedClass type)
    Checks if a given type is "Stringable", that is one of the default STRINGABLE_CLASSES, is an Enum, or is annotated with @Stringable and has a constructor that takes a single string argument capable of deserializing the output of its toString() method.
    static Object
    jsonNodeToObject(tools.jackson.databind.JsonNode defaultJsonValue)
     
    static tools.jackson.databind.JsonNode
     
    static org.apache.avro.Schema
    numericAvroSchema(tools.jackson.core.JsonParser.NumberType type)
     
    static org.apache.avro.Schema
    numericAvroSchema(tools.jackson.core.JsonParser.NumberType type, tools.jackson.databind.JavaType hint)
     
    static tools.jackson.databind.JsonNode
    objectToJsonNode(Object defaultValue)
     
    static tools.jackson.databind.JsonNode
    parseDefaultValue(String defaultValue)
    Converts a default value represented as a string (such as from a schema specification) into a JsonNode for further handling.
    static org.apache.avro.Schema
    Parses a JSON-formatted representation of a schema
    static org.apache.avro.Schema
    simpleSchema(tools.jackson.databind.jsonFormatVisitors.JsonFormatTypes type, tools.jackson.databind.JavaType hint)
     
    static org.apache.avro.Schema
    stringableKeyMapSchema(tools.jackson.databind.JavaType mapType, tools.jackson.databind.JavaType keyType, org.apache.avro.Schema valueSchema)
     
    protected static <T> T
     
    static org.apache.avro.Schema
    typedSchema(org.apache.avro.Schema.Type nativeType, tools.jackson.databind.JavaType javaType)
    Helper method for constructing type-tagged "native" Avro Schema instance.
    protected static org.apache.avro.Schema
    unionWithNull(org.apache.avro.Schema otherSchema)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • AVRO_SCHEMA_PROP_CLASS

      public static final String AVRO_SCHEMA_PROP_CLASS
      Constant used by native Avro Schemas for indicating more specific physical class of a value; referenced indirectly to reduce direct dependencies to the standard avro library.
      See Also:
    • AVRO_SCHEMA_PROP_KEY_CLASS

      public static final String AVRO_SCHEMA_PROP_KEY_CLASS
      Constant used by native Avro Schemas for indicating more specific physical class of a map key; referenced indirectly to reduce direct dependencies to the standard avro library.
      See Also:
    • AVRO_SCHEMA_PROP_ELEMENT_CLASS

      public static final String AVRO_SCHEMA_PROP_ELEMENT_CLASS
      Constant used by native Avro Schemas for indicating more specific physical class of a array element; referenced indirectly to reduce direct dependencies to the standard avro library.
      See Also:
    • STRINGABLE_CLASSES

      protected static final Set<Class<?>> STRINGABLE_CLASSES
      Default stringable classes
  • Constructor Details

    • AvroSchemaHelper

      public AvroSchemaHelper()
  • Method Details

    • isStringable

      public static boolean isStringable(tools.jackson.databind.introspect.AnnotatedClass type)
      Checks if a given type is "Stringable", that is one of the default STRINGABLE_CLASSES, is an Enum, or is annotated with @Stringable and has a constructor that takes a single string argument capable of deserializing the output of its toString() method.
      Parameters:
      type - Type to check if it can be serialized to a Avro string schema
      Returns:
      true if it can be stored in a string schema, otherwise false
    • getNamespace

      protected static String getNamespace(tools.jackson.databind.JavaType type, tools.jackson.databind.introspect.AnnotatedClass annotations)
    • getNamespace

      protected static String getNamespace(Class<?> cls)
    • getTypeName

      protected static String getTypeName(tools.jackson.databind.JavaType type)
    • unionWithNull

      protected static org.apache.avro.Schema unionWithNull(org.apache.avro.Schema otherSchema)
    • simpleSchema

      public static org.apache.avro.Schema simpleSchema(tools.jackson.databind.jsonFormatVisitors.JsonFormatTypes type, tools.jackson.databind.JavaType hint)
    • numericAvroSchema

      public static org.apache.avro.Schema numericAvroSchema(tools.jackson.core.JsonParser.NumberType type)
    • numericAvroSchema

      public static org.apache.avro.Schema numericAvroSchema(tools.jackson.core.JsonParser.NumberType type, tools.jackson.databind.JavaType hint)
    • typedSchema

      public static org.apache.avro.Schema typedSchema(org.apache.avro.Schema.Type nativeType, tools.jackson.databind.JavaType javaType)
      Helper method for constructing type-tagged "native" Avro Schema instance.
    • anyNumberSchema

      public static org.apache.avro.Schema anyNumberSchema()
    • stringableKeyMapSchema

      public static org.apache.avro.Schema stringableKeyMapSchema(tools.jackson.databind.JavaType mapType, tools.jackson.databind.JavaType keyType, org.apache.avro.Schema valueSchema)
    • throwUnsupported

      protected static <T> T throwUnsupported()
    • initializeRecordSchema

      public static org.apache.avro.Schema initializeRecordSchema(tools.jackson.databind.cfg.MapperConfig<?> config, tools.jackson.databind.JavaType type, tools.jackson.databind.introspect.AnnotatedClass annotations)
      Initializes a record schema with metadata from the given class; this schema is returned in a non-finalized state, and still needs to have fields added to it.
    • parseJsonSchema

      public static org.apache.avro.Schema parseJsonSchema(String json)
      Parses a JSON-formatted representation of a schema
    • createEnumSchema

      public static org.apache.avro.Schema createEnumSchema(tools.jackson.databind.cfg.MapperConfig<?> config, tools.jackson.databind.JavaType enumType, tools.jackson.databind.introspect.AnnotatedClass annotations, List<String> values)
      Constructs a new enum schema
      Parameters:
      values - List of enum names
      Returns:
      An ENUM schema.
    • createUUIDSchema

      public static org.apache.avro.Schema createUUIDSchema()
      Helper method to enclose details of expressing best Avro Schema for UUID: 16-byte fixed-length binary (alternative would be basic variable length "bytes").
    • addAlias

      public static org.apache.avro.Schema addAlias(org.apache.avro.Schema schema, tools.jackson.databind.introspect.AnnotatedClass annotations)
      Looks for @AvroAlias on bean and adds it to schema if it exists
      Parameters:
      schema - Schema to which the alias should be added
      annotations - Set of possibly relevant annotations
      Returns:
      schema, possibly with an alias added
    • getTypeId

      public static String getTypeId(tools.jackson.databind.JavaType type)
    • getTypeId

      public static String getTypeId(Class<?> type)
      Returns the Avro type ID for a given type
    • getTypeId

      public static String getTypeId(org.apache.avro.Schema schema)
      Returns the type ID for this schema, or null if none is present.
    • getFullName

      public static String getFullName(org.apache.avro.Schema schema)
      Returns the full name of a schema; This is similar to Schema.getFullName(), except that it properly handles namespaces for nested classes. (package.name.ClassName$NestedClassName instead of package.name.ClassName$.NestedClassName)

      WARNING! This method has to probe for nested classes in order to resolve whether or not a schema references a top-level class or a nested class and return the corresponding name for each.

    • nullNode

      public static tools.jackson.databind.JsonNode nullNode()
    • objectToJsonNode

      public static tools.jackson.databind.JsonNode objectToJsonNode(Object defaultValue)
    • jsonNodeToObject

      public static Object jsonNodeToObject(tools.jackson.databind.JsonNode defaultJsonValue)
    • parseDefaultValue

      public static tools.jackson.databind.JsonNode parseDefaultValue(String defaultValue) throws tools.jackson.databind.DatabindException
      Converts a default value represented as a string (such as from a schema specification) into a JsonNode for further handling.
      Parameters:
      defaultValue - The default value to parse, in the form of a JSON string
      Returns:
      a parsed JSON representation of the default value
      Throws:
      tools.jackson.databind.DatabindException - If defaultValue is not valid JSON