@InterfaceAudience.Public @InterfaceStability.Stable public interface Schema<T> extends Cloneable
Modifier and Type | Field and Description |
---|---|
static Schema<Boolean> |
BOOL
Boolean Schema.
|
static Schema<ByteBuffer> |
BYTEBUFFER
ByteBuffer Schema.
|
static Schema<byte[]> |
BYTES
Schema that doesn't perform any encoding on the message payloads.
|
static Schema<Date> |
DATE
Date Schema.
|
static Schema<Double> |
DOUBLE
Double Schema.
|
static Schema<Float> |
FLOAT
Float Schema.
|
static Schema<Instant> |
INSTANT
Instant Schema.
|
static Schema<Short> |
INT16
INT16 Schema.
|
static Schema<Integer> |
INT32
INT32 Schema.
|
static Schema<Long> |
INT64
INT64 Schema.
|
static Schema<Byte> |
INT8
INT8 Schema.
|
static Schema<LocalDate> |
LOCAL_DATE
LocalDate Schema.
|
static Schema<LocalDateTime> |
LOCAL_DATE_TIME
LocalDateTime Schema.
|
static Schema<LocalTime> |
LOCAL_TIME
LocalTime Schema.
|
static Schema<String> |
STRING
Schema that can be used to encode/decode messages whose values are String.
|
static Schema<Time> |
TIME
Time Schema.
|
static Schema<Timestamp> |
TIMESTAMP
Timestamp Schema.
|
Modifier and Type | Method and Description |
---|---|
static Schema<GenericRecord> |
AUTO_CONSUME()
Create a schema instance that automatically deserialize messages
based on the current topic schema.
|
static Schema<byte[]> |
AUTO_PRODUCE_BYTES()
Create a schema instance that accepts a serialized payload
and validates it against the topic schema.
|
static Schema<byte[]> |
AUTO_PRODUCE_BYTES(Schema<?> schema)
Create a schema instance that accepts a serialized payload
and validates it against the schema specified.
|
static Schema<GenericRecord> |
AUTO()
Deprecated.
|
static <T> Schema<T> |
AVRO(Class<T> pojo)
Create a Avro schema type by default configuration of the class.
|
static <T> Schema<T> |
AVRO(SchemaDefinition<T> schemaDefinition)
Create a Avro schema type with schema definition.
|
Schema<T> |
clone()
Duplicates the schema.
|
default void |
configureSchemaInfo(String topic,
String componentName,
SchemaInfo schemaInfo)
Configure the schema to use the provided schema info.
|
default T |
decode(byte[] bytes)
Decode a byte array into an object using the schema definition and deserializer implementation.
|
default T |
decode(byte[] bytes,
byte[] schemaVersion)
Decode a byte array into an object using a given version.
|
default T |
decode(ByteBuffer data,
byte[] schemaVersion)
Decode a ByteBuffer into an object using a given version.
|
byte[] |
encode(T message)
Encode an object representing the message content into a byte array.
|
static GenericSchema<GenericRecord> |
generic(SchemaInfo schemaInfo)
Returns a generic schema of existing schema info.
|
default Optional<Object> |
getNativeSchema()
Return the native schema that is wrapped by Pulsar API.
|
static Schema<?> |
getSchema(SchemaInfo schemaInfo) |
SchemaInfo |
getSchemaInfo() |
static <T> Schema<T> |
JSON(Class<T> pojo)
Create a JSON schema type by extracting the fields of the specified class.
|
static <T> Schema<T> |
JSON(SchemaDefinition schemaDefinition)
Create a JSON schema type with schema definition.
|
static <K,V> Schema<KeyValue<K,V>> |
KeyValue(Class<K> key,
Class<V> value)
Key Value Schema whose underneath key and value schemas are JSONSchema.
|
static <K,V> Schema<KeyValue<K,V>> |
KeyValue(Class<K> key,
Class<V> value,
SchemaType type)
Key Value Schema using passed in schema type, support JSON and AVRO currently.
|
static <K,V> Schema<KeyValue<K,V>> |
KeyValue(Schema<K> key,
Schema<V> value)
Key Value Schema using passed in key and value schemas.
|
static <K,V> Schema<KeyValue<K,V>> |
KeyValue(Schema<K> key,
Schema<V> value,
KeyValueEncodingType keyValueEncodingType)
Key Value Schema using passed in key, value and encoding type schemas.
|
static Schema<KeyValue<byte[],byte[]>> |
KV_BYTES()
Schema that can be used to encode/decode KeyValue.
|
static Schema<byte[]> |
NATIVE_AVRO(Object schema)
Create a schema instance that accepts a serialized Avro payload
without validating it against the schema specified.
|
static <T extends com.google.protobuf.GeneratedMessageV3> |
PROTOBUF_NATIVE(Class<T> clazz)
Create a Protobuf-Native schema type by extracting the fields of the specified class.
|
static <T extends com.google.protobuf.GeneratedMessageV3> |
PROTOBUF_NATIVE(SchemaDefinition<T> schemaDefinition)
Create a Protobuf-Native schema type with schema definition.
|
static <T extends com.google.protobuf.GeneratedMessageV3> |
PROTOBUF(Class<T> clazz)
Create a Protobuf schema type by extracting the fields of the specified class.
|
static <T extends com.google.protobuf.GeneratedMessageV3> |
PROTOBUF(SchemaDefinition<T> schemaDefinition)
Create a Protobuf schema type with schema definition.
|
default boolean |
requireFetchingSchemaInfo()
Check if this schema requires fetching schema info to configure the schema.
|
default void |
setSchemaInfoProvider(SchemaInfoProvider schemaInfoProvider) |
default boolean |
supportSchemaVersioning()
Returns whether this schema supports versioning.
|
default void |
validate(byte[] message)
Check if the message is a valid object for this schema.
|
static final Schema<byte[]> BYTES
static final Schema<ByteBuffer> BYTEBUFFER
static final Schema<String> STRING
static final Schema<LocalDateTime> LOCAL_DATE_TIME
default void validate(byte[] message)
The implementation can choose what its most efficient approach to validate the schema.
If the implementation doesn't provide it, it will attempt to use decode(byte[])
to see if this schema can decode this message or not as a validation mechanism to verify
the bytes.
message
- the messages to verifySchemaSerializationException
- if it is not a valid messagebyte[] encode(T message)
message
- the message objectSchemaSerializationException
- if the serialization failsdefault boolean supportSchemaVersioning()
Most of the schema implementations don't really support schema versioning, or it just doesn't
make any sense to support schema versionings (e.g. primitive schemas). Only schema returns
GenericRecord
should support schema versioning.
If a schema implementation returns false, it should implement decode(byte[])
;
while a schema implementation returns true, it should implement decode(byte[], byte[])
instead.
default void setSchemaInfoProvider(SchemaInfoProvider schemaInfoProvider)
default T decode(byte[] bytes)
bytes
- the byte array to decodedefault T decode(byte[] bytes, byte[] schemaVersion)
bytes
- the byte array to decodeschemaVersion
- the schema version to decode the object. null indicates using latest version.default T decode(ByteBuffer data, byte[] schemaVersion)
data
- the ByteBuffer to decodeschemaVersion
- the schema version to decode the object. null indicates using latest version.SchemaInfo getSchemaInfo()
default boolean requireFetchingSchemaInfo()
default void configureSchemaInfo(String topic, String componentName, SchemaInfo schemaInfo)
topic
- topic namecomponentName
- component nameschemaInfo
- schema infodefault Optional<Object> getNativeSchema()
static <T extends com.google.protobuf.GeneratedMessageV3> Schema<T> PROTOBUF(Class<T> clazz)
clazz
- the Protobuf generated class to be used to extract the schemastatic <T extends com.google.protobuf.GeneratedMessageV3> Schema<T> PROTOBUF(SchemaDefinition<T> schemaDefinition)
schemaDefinition
- schemaDefinition the definition of the schemastatic <T extends com.google.protobuf.GeneratedMessageV3> Schema<T> PROTOBUF_NATIVE(Class<T> clazz)
clazz
- the Protobuf generated class to be used to extract the schemastatic <T extends com.google.protobuf.GeneratedMessageV3> Schema<T> PROTOBUF_NATIVE(SchemaDefinition<T> schemaDefinition)
schemaDefinition
- schemaDefinition the definition of the schemastatic <T> Schema<T> AVRO(Class<T> pojo)
pojo
- the POJO class to be used to extract the Avro schemastatic <T> Schema<T> AVRO(SchemaDefinition<T> schemaDefinition)
schemaDefinition
- the definition of the schemastatic <T> Schema<T> JSON(Class<T> pojo)
pojo
- the POJO class to be used to extract the JSON schemastatic <T> Schema<T> JSON(SchemaDefinition schemaDefinition)
schemaDefinition
- the definition of the schemastatic <K,V> Schema<KeyValue<K,V>> KeyValue(Class<K> key, Class<V> value, SchemaType type)
static Schema<KeyValue<byte[],byte[]>> KV_BYTES()
static <K,V> Schema<KeyValue<K,V>> KeyValue(Class<K> key, Class<V> value)
static <K,V> Schema<KeyValue<K,V>> KeyValue(Schema<K> key, Schema<V> value)
static <K,V> Schema<KeyValue<K,V>> KeyValue(Schema<K> key, Schema<V> value, KeyValueEncodingType keyValueEncodingType)
@Deprecated static Schema<GenericRecord> AUTO()
static Schema<GenericRecord> AUTO_CONSUME()
The messages values are deserialized into a GenericRecord
object,
that extends the GenericObject
interface.
static Schema<byte[]> AUTO_PRODUCE_BYTES()
Currently this is only supported with Avro and JSON schema types.
This method can be used when publishing a raw JSON payload, for which the format is known and a POJO class is not available.
static Schema<byte[]> AUTO_PRODUCE_BYTES(Schema<?> schema)
AUTO_PRODUCE_BYTES()
static Schema<byte[]> NATIVE_AVRO(Object schema)
static Schema<?> getSchema(SchemaInfo schemaInfo)
static GenericSchema<GenericRecord> generic(SchemaInfo schemaInfo)
Only supports AVRO and JSON.
schemaInfo
- schema infoCopyright © 2017–2021 Apache Software Foundation. All rights reserved.