Interface ObjectSerializer<T>
- Type Parameters:
T- the type of the object to serialize.
public interface ObjectSerializer<T>
A serializer for a specific type of object to be serialized into a network buffer.
- Since:
- 4.0
-
Method Summary
Modifier and TypeMethodDescriptiondefault booleanpreReadCheckAccepts(@NonNull Type type, @NonNull ObjectMapper caller) A method being called before a serializer is chosen to deserialize an object of the given type.default booleanpreWriteCheckAccepts(T object, @NonNull ObjectMapper caller) A method being called before a serializer is chosen to serialize the requested object.Reads the object from the buffer.voidwrite(DataBuf.Mutable dataBuf, T object, @NonNull Type type, @NonNull ObjectMapper caller) Writes the given object into the given buffer for network transfer and later deserialization.
-
Method Details
-
read
@Nullable @Nullable Object read(@NonNull @NonNull DataBuf source, @NonNull @NonNull Type type, @NonNull @NonNull ObjectMapper caller) Reads the object from the buffer. This method should only read the content from the buffer which was written to it previously, never more as the given buffer is not a slice of the buffer representing the object being read. Although this method returns an object, the returned object must always match the given type during object construction. The object return type is just a helper, but the return value will be cast to the given type resulting in errors if provided with the wrong type of object.- Parameters:
source- the buffer to read the object from.type- the type of the object to read.caller- the mapper to which this serializer is registered and from which the deserialize request call came.- Returns:
- the deserialized object of the serializer type T, or null if not readable.
- Throws:
NullPointerException- if either the given source, type or mapper is null.
-
write
void write(@NonNull DataBuf.Mutable dataBuf, @NonNull T object, @NonNull @NonNull Type type, @NonNull @NonNull ObjectMapper caller) Writes the given object into the given buffer for network transfer and later deserialization.- Parameters:
dataBuf- the buffer to write the data to.object- the object to serialize.type- the raw type of the object.caller- the object mapper to which this serializer belongs and which requested the serialisation.- Throws:
NullPointerException- if one of the given arguments is null.
-
preWriteCheckAccepts
A method being called before a serializer is chosen to serialize the requested object. If true is returned, the serializer will be used for serialization of the object (default behaviour), when false is returned the object mapper tries to find another serializer for the object.- Parameters:
object- the object which should get written to the buffer.caller- the object mapper to which the serialisation request was made and this serializer belongs to.- Returns:
- true if the given object should be serialized by this serializer, false otherwise.
- Throws:
NullPointerException- if either the given object or mapper is null.
-
preReadCheckAccepts
default boolean preReadCheckAccepts(@NonNull @NonNull Type type, @NonNull @NonNull ObjectMapper caller) A method being called before a serializer is chosen to deserialize an object of the given type. If true is returned, the serializer will be used for deserialization of the object (default behaviour), when false is returned the object mapper tries to find another deserializer for the object.- Parameters:
type- the type of the object which should get deserialized.caller- the object mapper to which the deserialization request was made and this serializer belongs to.- Returns:
- true if the given object should be deserialized by this serializer, false otherwise.
- Throws:
NullPointerException- if either the given object type or mapper is null.
-