Interface SerializerRegistry<S>
- Type Parameters:
S
- a type of objects after serializing
public sealed interface SerializerRegistry<S>
A registry that manages
Serializer
s.
The implementations of this interface are thread-safe.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <S> @NotNull SerializerRegistry<S>
create()
Creates a newSerializerRegistry
.static <S> @NotNull SerializerRegistry<S>
empty()
Returns an emptySerializerRegistry
.@NotNull SerializerRegistry<S>
freeze()
Freezes thisSerializerRegistry
.<T> @Nullable Serializer<T,
S> Gets theSerializer
associated with the specified class.default <T> @NotNull Optional<Serializer<T,
S>> getAsOptional
(@NotNull Class<T> clazz) Gets theSerializer
associated with the specified class.boolean
isFrozen()
Checks if thisSerializerRegistry
is frozen.<T> @NotNull SerializerRegistry<S>
register
(@NotNull Class<T> clazz, @NotNull Serializer<? super T, ? extends S> serializer) RegistersSerializer
.@NotNull SerializerRegistry<S>
registerAll
(@NotNull SerializerRegistry<S> registry) RegistersSerializer
s in the givenSerializerRegistry
.
-
Method Details
-
create
Creates a newSerializerRegistry
.- Type Parameters:
S
- a type of objects after serializing- Returns:
- a new
SerializerRegistry
-
empty
Returns an emptySerializerRegistry
.The returning
SerializerRegistry
is frozen.- Type Parameters:
S
- a type of objects after serializing- Returns:
- an empty
SerializerRegistry
-
get
Gets theSerializer
associated with the specified class.- Type Parameters:
T
- a type of object to serialize- Parameters:
clazz
- the class to getSerializer
- Returns:
- the
Serializer
associated with the specified class, ornull
-
getAsOptional
@NotNull default <T> @NotNull Optional<Serializer<T,S>> getAsOptional(@NotNull @NotNull Class<T> clazz) Gets theSerializer
associated with the specified class.- Type Parameters:
T
- a type of object to serialize- Parameters:
clazz
- the class to getSerializer
- Returns:
- the
Serializer
associated with the specified class, orOptional.empty()
-
register
@Contract("_, _ -> this") @NotNull <T> @NotNull SerializerRegistry<S> register(@NotNull @NotNull Class<T> clazz, @NotNull @NotNull Serializer<? super T, ? extends S> serializer) RegistersSerializer
.- Type Parameters:
T
- a type of object to serialize- Parameters:
clazz
- a class to associateSerializer
withserializer
- aSerializer
to register- Returns:
- this
SerializerRegistry
instance
-
registerAll
@Contract("_ -> this") @NotNull @NotNull SerializerRegistry<S> registerAll(@NotNull @NotNull SerializerRegistry<S> registry) RegistersSerializer
s in the givenSerializerRegistry
.- Parameters:
registry
- aSerializerRegistry
that containsSerializer
s to register- Returns:
- this
SerializerRegistry
instance
-
freeze
Freezes thisSerializerRegistry
.After calling this method,
register(Class, Serializer)
andregisterAll(SerializerRegistry)
will throwIllegalStateException
.This method can be called multiple times.
- Returns:
- this
SerializerRegistry
instance
-
isFrozen
boolean isFrozen()Checks if thisSerializerRegistry
is frozen.- Returns:
true
if thisSerializerRegistry
is frozen, otherwisefalse
-