Class DataClassSerializer
java.lang.Object
eu.cloudnetservice.driver.network.rpc.defaults.object.data.DataClassSerializer
- All Implemented Interfaces:
ObjectSerializer<Object>
A serializer for all data classes and arrays which have no special serializer available.
- Since:
- 4.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final com.github.benmanes.caffeine.cache.LoadingCache<Type,DataClassInformation> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReads the object from the buffer.Reads an array from the given data buf source.voidwrite(DataBuf.Mutable dataBuf, @NonNull Object object, @NonNull Type type, @NonNull ObjectMapper caller) Writes the given object into the given buffer for network transfer and later deserialization.protected voidwriteArray(DataBuf.Mutable dataBuf, @NonNull Object object, @NonNull ObjectMapper caller) Writes the given array to the given data buffer.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
-
dataClassInformationCache
private final com.github.benmanes.caffeine.cache.LoadingCache<Type,DataClassInformation> dataClassInformationCache
-
-
Constructor Details
-
DataClassSerializer
public DataClassSerializer()
-
-
Method Details
-
read
@Nullable public @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.- Specified by:
readin interfaceObjectSerializer<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.
-
write
public void write(@NonNull DataBuf.Mutable dataBuf, @NonNull @NonNull Object 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<Object>- 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.
-
readArray
@Nullable protected @Nullable Object readArray(@NonNull @NonNull DataBuf source, @NonNull @NonNull Class<?> clazz, @NonNull @NonNull ObjectMapper caller) Reads an array from the given data buf source.- Parameters:
source- the buffer to read the array from.clazz- the type of the array to read.caller- the object mapper used for deserialization of the entries.- Returns:
- the read array from the buffer.
- Throws:
NullPointerException- if either the given buffer, type or object mapper is null.
-
writeArray
protected void writeArray(@NonNull DataBuf.Mutable dataBuf, @NonNull @NonNull Object object, @NonNull @NonNull ObjectMapper caller) Writes the given array to the given data buffer.- Parameters:
dataBuf- the buffer to write the array to.object- the array to write.caller- the object mapper to serialize the array to.- Throws:
NullPointerException- if the given buffer, array or object mapper is null.
-