Interface SerializationRegistry<S>
- Type Parameters:
S
- a type of objects after serializing
Serialization
s.
The implementations of this interface are thread-safe.
-
Method Summary
Modifier and TypeMethodDescription@NotNull DeserializerRegistry<S>
Gets theDeserializerRegistry
that refers thisSerializationRegistry
.@NotNull SerializerRegistry<S>
Gets theSerializerRegistry
that 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 theSerialization
associated with the specified class.default <T> @NotNull Optional<Serialization<T,
S>> getAsOptional
(@NotNull Class<T> clazz) Gets theSerialization
associated with the specified class.boolean
isFrozen()
Checks if thisSerializationRegistry
is 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) RegistersSerialization
s 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
SerializationRegistry
is frozen.- Type Parameters:
S
- a type of objects after serializing- Returns:
- an empty
SerializationRegistry
-
get
Gets theSerialization
associated with the specified class.- Type Parameters:
T
- a type of objects after serializing- Parameters:
clazz
- the class to getSerialization
- Returns:
- the
Serialization
associated with the specified class, ornull
-
getAsOptional
@NotNull default <T> @NotNull Optional<Serialization<T,S>> getAsOptional(@NotNull @NotNull Class<T> clazz) Gets theSerialization
associated with the specified class.- Type Parameters:
T
- a type of objects after serializing- Parameters:
clazz
- the class to getSerialization
- Returns:
- the
Serialization
associated 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 associateSerialization
withserialization
- aSerialization
to register- Returns:
- this
SerializationRegistry
instance
-
registerAll
@Contract("_ -> this") @NotNull @NotNull SerializationRegistry<S> registerAll(@NotNull @NotNull SerializationRegistry<S> registry) RegistersSerialization
s in the givenSerializationRegistry
.- Parameters:
registry
- aSerialization
that containsSerialization
s to register- Returns:
- this
SerializationRegistry
instance
-
freeze
Freezes thisSerializationRegistry
.After calling this method,
register(Class, Serialization)
andregisterAll(SerializationRegistry)
will throwIllegalStateException
.This method can be called multiple times.
- Returns:
- this
SerializationRegistry
instance
-
isFrozen
boolean isFrozen()Checks if thisSerializationRegistry
is frozen.- Returns:
true
if thisSerializationRegistry
is frozen, otherwisefalse
-
asSerializerRegistry
Gets theSerializerRegistry
that refers thisSerializationRegistry
.When calling
SerializerRegistry.register(Class, Serializer)
orSerializerRegistry.registerAll(SerializerRegistry)
, the returningSerializerRegistry
will register it to this registry usingSerialization.onlySerializer(Serializer)
orSerialization.create(Serializer, Deserializer)
(ifDeserializer
exists)- Returns:
- the
SerializerRegistry
that refers thisSerializationRegistry
-
asDeserializerRegistry
Gets theDeserializerRegistry
that refers thisSerializationRegistry
.When calling
DeserializerRegistry.register(Class, Deserializer)
orDeserializerRegistry.registerAll(DeserializerRegistry)
, the returningDeserializerRegistry
will register it to this registry usingSerialization.onlyDeserializer(Deserializer)
orSerialization.create(Serializer, Deserializer)
(ifSerializer
exists)- Returns:
- the
DeserializerRegistry
that refers thisSerializationRegistry
-