Class MapObjectSerializer
java.lang.Object
eu.cloudnetservice.driver.network.rpc.defaults.object.serializers.MapObjectSerializer
- All Implemented Interfaces:
ObjectSerializer<Map<?,?>>
An object serializer which can de- serialize any kind of map from/to a buffer.
- Since:
- 4.0
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedMapObjectSerializer(@NonNull Supplier<Map<?, ?>> mapFactory) Constructs a new map object serializer instance. -
Method Summary
Modifier and TypeMethodDescriptionstatic @NonNull MapObjectSerializerConstructs a new map object serializer instance.Reads the object from the buffer.voidwrite(DataBuf.Mutable dataBuf, @Nullable Map<?, ?> object, @NonNull Type type, @NonNull ObjectMapper caller) Writes the given object into the given buffer for network transfer and later deserialization.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface eu.cloudnetservice.driver.network.rpc.object.ObjectSerializer
preReadCheckAccepts, preWriteCheckAccepts
-
Field Details
-
mapFactory
-
-
Constructor Details
-
MapObjectSerializer
Constructs a new map object serializer instance.- Parameters:
mapFactory- the map factory to use to construct the map instances.- Throws:
NullPointerException- if the given map factory is null.
-
-
Method Details
-
of
@NonNull public static @NonNull MapObjectSerializer of(@NonNull @NonNull Supplier<Map<?, ?>> mapFactory) Constructs a new map object serializer instance.- Parameters:
mapFactory- the map factory to use to construct the map instances.- Returns:
- the created map object serializer instance.
- Throws:
NullPointerException- if the given map factory is null.
-
read
@Nullable public @Nullable Map<?,?> 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.- Specified by:
readin interfaceObjectSerializer<Map<?,?>> - 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.
-
write
public void write(@NonNull DataBuf.Mutable dataBuf, @Nullable @Nullable Map<?, ?> object, @NonNull @NonNull Type type, @NonNull @NonNull ObjectMapper caller) Writes the given object into the given buffer for network transfer and later deserialization.- Specified by:
writein interfaceObjectSerializer<Map<?,?>> - 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.
-