Interface ObjectMapper
public interface ObjectMapper
Represents the registry for object serializers and is the base class to read/write an object to a buffer.
- Since:
- 4.0
-
Method Summary
Modifier and TypeMethodDescription<T> @UnknownNullability TreadObject(@NonNull DataBuf dataBuf, @NonNull Type type) Reads an object from the given buffer by the given type using the previously registered serializers.<T> @NonNull ObjectMapperregisterBinding(@NonNull Type type, @NonNull ObjectSerializer<T> serializer, boolean superTypes) Registers the given object serializer to this mapper, including all super types of the given type if requested.unregisterBinding(@NonNull Type type, boolean superTypes) Unregisters all object serializers which were registered for the given type, include all super types of the given type if requested.unregisterBindings(@NonNull ClassLoader classLoader) Unregisters all object serializers whose classes were loaded by the given class loader.<T> DataBuf.MutablewriteObject(DataBuf.Mutable dataBuf, T object) Writes the given object into the given data buffer using the previously registered object serializers.
-
Method Details
-
unregisterBinding
Unregisters all object serializers which were registered for the given type, include all super types of the given type if requested.- Parameters:
type- the base type of the mappers to unregister.superTypes- if all super types of the base type should get included when unregistering.- Returns:
- the same instance as used to call the method, for chaining.
- Throws:
NullPointerException- if the given base type is null.
-
unregisterBindings
Unregisters all object serializers whose classes were loaded by the given class loader.- Parameters:
classLoader- the class loader of the object serializers to unregister.- Returns:
- the same instance as used to call the method, for chaining.
- Throws:
NullPointerException- if the given class loader is null.
-
registerBinding
@NonNull <T> @NonNull ObjectMapper registerBinding(@NonNull @NonNull Type type, @NonNull @NonNull ObjectSerializer<T> serializer, boolean superTypes) Registers the given object serializer to this mapper, including all super types of the given type if requested. This call will silently be ignored if previously a mapper was registered for one of the requested types.- Type Parameters:
T- the generic type of the object serializer to register.- Parameters:
type- the type which can be (de-) serialized using the given serializer.serializer- the serializer to use for the type.superTypes- if all super types of the given type should get associated with the given serializer as well.- Returns:
- the same instance as used to call the method, for chaining.
- Throws:
NullPointerException- if either the given type or serializer is null.
-
writeObject
Writes the given object into the given data buffer using the previously registered object serializers.- Type Parameters:
T- the generic type of the object to serialize.- Parameters:
dataBuf- the buffer to serialize the data to.object- the object to serialize into the buffer, can be null.- Returns:
- the same buffer used to call the method, for further writing.
- Throws:
NullPointerException- if the given buffer is null.MissingObjectSerializerException- if no serializer was found to serialize the given object.
-
readObject
<T> @UnknownNullability T readObject(@NonNull @NonNull DataBuf dataBuf, @NonNull @NonNull Type type) Reads an object from the given buffer by the given type using the previously registered serializers. The returned object might be null if the object written to the buffer was null as well.- Type Parameters:
T- the generic type of the object.- Parameters:
dataBuf- the buffer from which the object should get deserialized.type- the type of the object to deserialize.- Returns:
- the deserialized object from the buffer, can be null.
- Throws:
NullPointerException- if either the given buffer or type is null.MissingObjectSerializerException- if no serializer was found to deserialize the given object.
-