Class AbstractDeserializationSchema<T>
- java.lang.Object
-
- org.apache.flink.api.common.serialization.AbstractDeserializationSchema<T>
-
- Type Parameters:
T
- The type created by the deserialization schema.
- All Implemented Interfaces:
Serializable
,DeserializationSchema<T>
,ResultTypeQueryable<T>
- Direct Known Subclasses:
AvroRowDeserializationSchema
,JsonDeserializationSchema
@PublicEvolving public abstract class AbstractDeserializationSchema<T> extends Object implements DeserializationSchema<T>
The deserialization schema describes how to turn the byte messages delivered by certain data sources (for example Apache Kafka) into data types (Java/Scala objects) that are processed by Flink.This base variant of the deserialization schema produces the type information automatically by extracting it from the generic class arguments.
Common Use
To write a deserialization schema for a specific type, simply extend this class and declare the type in the class signature. Flink will reflectively determine the type and create the proper TypeInformation:
public class MyDeserializationSchema extends AbstractDeserializationSchema<MyType> { public MyType deserialize(byte[] message) throws IOException { ... } }
Generic Use
If you want to write a more generic DeserializationSchema that works for different types, you need to pass the TypeInformation (or an equivalent hint) to the constructor:
public class MyGenericSchema<T> extends AbstractDeserializationSchema<T> { public MyGenericSchema(Class<T> type) { super(type); } public T deserialize(byte[] message) throws IOException { ... } }
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.flink.api.common.serialization.DeserializationSchema
DeserializationSchema.InitializationContext
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractDeserializationSchema()
Creates a new AbstractDeserializationSchema and tries to infer the type returned by this DeserializationSchema.protected
AbstractDeserializationSchema(Class<T> type)
Creates an AbstractDeserializationSchema that returns the TypeInformation indicated by the given class.protected
AbstractDeserializationSchema(TypeHint<T> typeHint)
Creates an AbstractDeserializationSchema that returns the TypeInformation indicated by the given type hint.protected
AbstractDeserializationSchema(TypeInformation<T> typeInfo)
Creates an AbstractDeserializationSchema that returns the given TypeInformation for the produced type.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract T
deserialize(byte[] message)
De-serializes the byte message.TypeInformation<T>
getProducedType()
Gets the type produced by this deserializer.boolean
isEndOfStream(T nextElement)
Method to decide whether the element signals the end of the stream.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.flink.api.common.serialization.DeserializationSchema
deserialize, open
-
-
-
-
Constructor Detail
-
AbstractDeserializationSchema
protected AbstractDeserializationSchema()
Creates a new AbstractDeserializationSchema and tries to infer the type returned by this DeserializationSchema.This constructor is usable whenever the DeserializationSchema concretely defines its type, without generic variables:
public class MyDeserializationSchema extends AbstractDeserializationSchema<MyType> { public MyType deserialize(byte[] message) throws IOException { ... } }
-
AbstractDeserializationSchema
protected AbstractDeserializationSchema(Class<T> type)
Creates an AbstractDeserializationSchema that returns the TypeInformation indicated by the given class. This constructor is only necessary when creating a generic implementation, seeGeneric Use
.This constructor may fail if the class is generic. In that case, please use the constructor that accepts a
TypeHint
, or aTypeInformation
.- Parameters:
type
- The class of the produced type.
-
AbstractDeserializationSchema
protected AbstractDeserializationSchema(TypeHint<T> typeHint)
Creates an AbstractDeserializationSchema that returns the TypeInformation indicated by the given type hint. This constructor is only necessary when creating a generic implementation, seeGeneric Use
.- Parameters:
typeHint
- The TypeHint for the produced type.
-
AbstractDeserializationSchema
protected AbstractDeserializationSchema(TypeInformation<T> typeInfo)
Creates an AbstractDeserializationSchema that returns the given TypeInformation for the produced type. This constructor is only necessary when creating a generic implementation, seeGeneric Use
.- Parameters:
typeInfo
- The TypeInformation for the produced type.
-
-
Method Detail
-
deserialize
public abstract T deserialize(byte[] message) throws IOException
De-serializes the byte message.- Specified by:
deserialize
in interfaceDeserializationSchema<T>
- Parameters:
message
- The message, as a byte array.- Returns:
- The de-serialized message as an object.
- Throws:
IOException
-
isEndOfStream
public boolean isEndOfStream(T nextElement)
Method to decide whether the element signals the end of the stream. If true is returned the element won't be emitted.This default implementation returns always false, meaning the stream is interpreted to be unbounded.
- Specified by:
isEndOfStream
in interfaceDeserializationSchema<T>
- Parameters:
nextElement
- The element to test for the end-of-stream signal.- Returns:
- True, if the element signals end of stream, false otherwise.
-
getProducedType
public TypeInformation<T> getProducedType()
Gets the type produced by this deserializer. This is the type that was passed to the constructor, or reflectively inferred (if the default constructor was called).- Specified by:
getProducedType
in interfaceResultTypeQueryable<T>
- Returns:
- The data type produced by this function or input format.
-
-