Class SchemaBuilder.BaseTypeBuilder<R>

java.lang.Object
org.apache.avro.SchemaBuilder.BaseTypeBuilder<R>
Direct Known Subclasses:
SchemaBuilder.TypeBuilder
Enclosing class:
SchemaBuilder

public static class SchemaBuilder.BaseTypeBuilder<R> extends Object
A common API for building types within a context. BaseTypeBuilder can build all types other than Unions. SchemaBuilder.TypeBuilder can additionally build Unions.

The builder has two contexts:

  • A naming context provides a default namespace and allows for previously defined named types to be referenced from type(String)
  • A completion context representing the scope that the builder was created in. A builder created in a nested context (for example, SchemaBuilder.MapBuilder.values() will have a completion context assigned by the SchemaBuilder.MapBuilder
    • Method Details

      • type

        public final R type(Schema schema)
        Use the schema provided as the type.
      • type

        public final R type(String name)
        Look up the type by name. This type must be previously defined in the context of this builder.

        The name may be fully qualified or a short name. If it is a short name, the default namespace of the current context will additionally be searched.

      • type

        public final R type(String name, String namespace)
        Look up the type by name and namespace. This type must be previously defined in the context of this builder.

        The name may be fully qualified or a short name. If it is a fully qualified name, the namespace provided is ignored. If it is a short name, the namespace provided is used if not null, else the default namespace of the current context will be used.

      • booleanType

        public final R booleanType()
        A plain boolean type without custom properties. This is equivalent to:
         booleanBuilder().endBoolean();
         
      • booleanBuilder

        public final SchemaBuilder.BooleanBuilder<R> booleanBuilder()
        Build a boolean type that can set custom properties. If custom properties are not needed it is simpler to use booleanType().
      • intType

        public final R intType()
        A plain int type without custom properties. This is equivalent to:
         intBuilder().endInt();
         
      • intBuilder

        public final SchemaBuilder.IntBuilder<R> intBuilder()
        Build an int type that can set custom properties. If custom properties are not needed it is simpler to use intType().
      • longType

        public final R longType()
        A plain long type without custom properties. This is equivalent to:
         longBuilder().endLong();
         
      • longBuilder

        public final SchemaBuilder.LongBuilder<R> longBuilder()
        Build a long type that can set custom properties. If custom properties are not needed it is simpler to use longType().
      • floatType

        public final R floatType()
        A plain float type without custom properties. This is equivalent to:
         floatBuilder().endFloat();
         
      • floatBuilder

        public final SchemaBuilder.FloatBuilder<R> floatBuilder()
        Build a float type that can set custom properties. If custom properties are not needed it is simpler to use floatType().
      • doubleType

        public final R doubleType()
        A plain double type without custom properties. This is equivalent to:
         doubleBuilder().endDouble();
         
      • doubleBuilder

        public final SchemaBuilder.DoubleBuilder<R> doubleBuilder()
        Build a double type that can set custom properties. If custom properties are not needed it is simpler to use doubleType().
      • stringType

        public final R stringType()
        A plain string type without custom properties. This is equivalent to:
         stringBuilder().endString();
         
      • stringBuilder

        public final SchemaBuilder.StringBldr<R> stringBuilder()
        Build a string type that can set custom properties. If custom properties are not needed it is simpler to use stringType().
      • bytesType

        public final R bytesType()
        A plain bytes type without custom properties. This is equivalent to:
         bytesBuilder().endBytes();
         
      • bytesBuilder

        public final SchemaBuilder.BytesBuilder<R> bytesBuilder()
        Build a bytes type that can set custom properties. If custom properties are not needed it is simpler to use bytesType().
      • nullType

        public final R nullType()
        A plain null type without custom properties. This is equivalent to:
         nullBuilder().endNull();
         
      • nullBuilder

        public final SchemaBuilder.NullBuilder<R> nullBuilder()
        Build a null type that can set custom properties. If custom properties are not needed it is simpler to use nullType().
      • map

        public final SchemaBuilder.MapBuilder<R> map()
        Build an Avro map type Example usage:
         map().values().intType()
         
        Equivalent to Avro JSON Schema:
         {"type":"map", "values":"int"}
         
      • array

        public final SchemaBuilder.ArrayBuilder<R> array()
        Build an Avro array type Example usage:
         array().items().longType()
         
        Equivalent to Avro JSON Schema:
         {"type":"array", "values":"long"}
         
      • fixed

        public final SchemaBuilder.FixedBuilder<R> fixed(String name)
        Build an Avro fixed type. Example usage:
         fixed("com.foo.IPv4").size(4)
         
        Equivalent to Avro JSON Schema:
         {"type":"fixed", "name":"com.foo.IPv4", "size":4}
         
      • enumeration

        public final SchemaBuilder.EnumBuilder<R> enumeration(String name)
        Build an Avro enum type. Example usage:
         enumeration("Suits").namespace("org.cards").doc("card suit names").defaultSymbol("HEART").symbols("HEART", "SPADE",
             "DIAMOND", "CLUB")
         
        Equivalent to Avro JSON Schema:
         {"type":"enum", "name":"Suits", "namespace":"org.cards",
          "doc":"card suit names", "symbols":[
            "HEART", "SPADE", "DIAMOND", "CLUB"], "default":"HEART"}
         
      • record

        public final SchemaBuilder.RecordBuilder<R> record(String name)
        Build an Avro record type. Example usage:
         record("com.foo.Foo").fields().name("field1").typeInt().intDefault(1).name("field2").typeString().noDefault()
             .name("field3").optional().typeFixed("FooFixed").size(4).endRecord()
         
        Equivalent to Avro JSON Schema:
         {"type":"record", "name":"com.foo.Foo", "fields": [
           {"name":"field1", "type":"int", "default":1},
           {"name":"field2", "type":"string"},
           {"name":"field3", "type":[
             null, {"type":"fixed", "name":"FooFixed", "size":4}
             ]}
           ]}
         
      • unionOf

        Build an Avro union schema type. Example usage:
         unionOf().stringType().and().bytesType().endUnion()
         
      • nullable

        protected SchemaBuilder.BaseTypeBuilder<R> nullable()
        A shortcut for building a union of a type and null.

        For example, the code snippets below are equivalent:

         nullable().booleanType()
         
         unionOf().booleanType().and().nullType().endUnion()