public interface Schema<T>
Modifier and Type | Field and Description |
---|---|
static Schema<byte[]> |
BYTES
Schema that doesn't perform any encoding on the message payloads.
|
static Schema<KeyValue<byte[],byte[]>> |
KV_BYTES
Schema that can be used to encode/decode KeyValue.
|
static Schema<String> |
STRING
Schema that can be used to encode/decode messages whose values are String.
|
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<GenericRecord> |
AUTO()
Deprecated.
|
static <T> Schema<T> |
AVRO(Class<T> clazz)
Create a Avro schema type by extracting the fields of the specified class.
|
T |
decode(byte[] bytes)
Decode a byte array into an object using the schema definition and deserializer implementation
|
byte[] |
encode(T message)
Encode an object representing the message content into a byte array.
|
static Schema<?> |
getSchema(SchemaInfo schemaInfo) |
SchemaInfo |
getSchemaInfo() |
static <T> Schema<T> |
JSON(Class<T> clazz)
Create a JSON schema type by extracting the fields of the specified class.
|
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 <T extends com.google.protobuf.GeneratedMessageV3> |
PROTOBUF(Class<T> clazz)
Create a Protobuf schema type by extracting the fields of the specified class.
|
default void |
validate(byte[] message)
Check if the message is a valid object for this schema.
|
static final Schema<byte[]> BYTES
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 failsT decode(byte[] bytes)
bytes
- the byte array to decodeSchemaInfo 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> Schema<T> AVRO(Class<T> clazz)
clazz
- the POJO class to be used to extract the Avro schemastatic <T> Schema<T> JSON(Class<T> clazz)
clazz
- the POJO class to be used to extract the JSON schemastatic <K,V> Schema<KeyValue<K,V>> KeyValue(Class<K> key, Class<V> value, SchemaType type)
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)
@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)
Copyright © 2017–2019 Apache Software Foundation. All rights reserved.