Interface SerializationRegistry<S>
- Type Parameters:
S- a type of objects after serializing
Serializations.
The implementations of this interface are thread-safe.
-
Method Summary
Modifier and TypeMethodDescription@NotNull DeserializerRegistry<S>Gets theDeserializerRegistrythat refers thisSerializationRegistry.@NotNull SerializerRegistry<S>Gets theSerializerRegistrythat refers thisSerializationRegistry.static <S> @NotNull SerializationRegistry<S>create()Creates a newSerializationRegistry.static <S> @NotNull SerializationRegistry<S>empty()Returns an emptySerializationRegistry.@NotNull SerializationRegistry<S>freeze()Freezes thisSerializationRegistry.<T> @Nullable Serialization<T,S> Gets theSerializationassociated with the specified class.default <T> @NotNull Optional<Serialization<T,S>> getAsOptional(@NotNull Class<T> clazz) Gets theSerializationassociated with the specified class.booleanisFrozen()Checks if thisSerializationRegistryis frozen.<T> @NotNull SerializationRegistry<S>register(@NotNull Class<T> clazz, @NotNull Serialization<? super T, ? extends S> serialization) RegistersSerialization.@NotNull SerializationRegistry<S>registerAll(@NotNull SerializationRegistry<S> registry) RegistersSerializations in the givenSerializationRegistry.
-
Method Details
-
create
Creates a newSerializationRegistry.- Type Parameters:
S- a type of objects after serializing- Returns:
- a new
SerializationRegistry
-
empty
Returns an emptySerializationRegistry.The returning
SerializationRegistryis frozen.- Type Parameters:
S- a type of objects after serializing- Returns:
- an empty
SerializationRegistry
-
get
Gets theSerializationassociated with the specified class.- Type Parameters:
T- a type of objects after serializing- Parameters:
clazz- the class to getSerialization- Returns:
- the
Serializationassociated with the specified class, ornull
-
getAsOptional
@NotNull default <T> @NotNull Optional<Serialization<T,S>> getAsOptional(@NotNull @NotNull Class<T> clazz) Gets theSerializationassociated with the specified class.- Type Parameters:
T- a type of objects after serializing- Parameters:
clazz- the class to getSerialization- Returns:
- the
Serializationassociated with the specified class, orOptional.empty()
-
register
@Contract("_, _ -> this") @NotNull <T> @NotNull SerializationRegistry<S> register(@NotNull @NotNull Class<T> clazz, @NotNull @NotNull Serialization<? super T, ? extends S> serialization) RegistersSerialization.- Type Parameters:
T- a type of objects after serializing- Parameters:
clazz- a class to associateSerializationwithserialization- aSerializationto register- Returns:
- this
SerializationRegistryinstance
-
registerAll
@Contract("_ -> this") @NotNull @NotNull SerializationRegistry<S> registerAll(@NotNull @NotNull SerializationRegistry<S> registry) RegistersSerializations in the givenSerializationRegistry.- Parameters:
registry- aSerializationthat containsSerializations to register- Returns:
- this
SerializationRegistryinstance
-
freeze
Freezes thisSerializationRegistry.After calling this method,
register(Class, Serialization)andregisterAll(SerializationRegistry)will throwIllegalStateException.This method can be called multiple times.
- Returns:
- this
SerializationRegistryinstance
-
isFrozen
boolean isFrozen()Checks if thisSerializationRegistryis frozen.- Returns:
trueif thisSerializationRegistryis frozen, otherwisefalse
-
asSerializerRegistry
Gets theSerializerRegistrythat refers thisSerializationRegistry.When calling
SerializerRegistry.register(Class, Serializer)orSerializerRegistry.registerAll(SerializerRegistry), the returningSerializerRegistrywill register it to this registry usingSerialization.onlySerializer(Serializer)orSerialization.create(Serializer, Deserializer)(ifDeserializerexists)- Returns:
- the
SerializerRegistrythat refers thisSerializationRegistry
-
asDeserializerRegistry
Gets theDeserializerRegistrythat refers thisSerializationRegistry.When calling
DeserializerRegistry.register(Class, Deserializer)orDeserializerRegistry.registerAll(DeserializerRegistry), the returningDeserializerRegistrywill register it to this registry usingSerialization.onlyDeserializer(Deserializer)orSerialization.create(Serializer, Deserializer)(ifSerializerexists)- Returns:
- the
DeserializerRegistrythat refers thisSerializationRegistry
-