public interface Schema<T>
限定符和类型 | 字段和说明 |
---|---|
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<Short> |
INT16
INT16 Schema
|
static Schema<Integer> |
INT32
INT32 Schema
|
static Schema<Long> |
INT64
INT64 Schema
|
static Schema<Byte> |
INT8
INT8 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
|
限定符和类型 | 方法和说明 |
---|---|
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<GenericRecord> |
AUTO()
已过时。
|
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
|
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.
|
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.
|
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 <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 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
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.SchemaInfo getSchemaInfo()
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> 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.
Currently this is only supported with Avro and JSON schema types.
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 avaialable.
static Schema<?> getSchema(SchemaInfo schemaInfo)
static GenericSchema<GenericRecord> generic(SchemaInfo schemaInfo)
Only supports AVRO and JSON.
schemaInfo
- schema infoCopyright © 2017–2019 Apache Software Foundation. All rights reserved.