Interface SerializerRegistry<S>
- Type Parameters:
S- a type of objects after serializing
public sealed interface SerializerRegistry<S>
A registry that manages
Serializers.
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 theSerializerassociated with the specified class.default <T> @NotNull Optional<Serializer<T,S>> getAsOptional(@NotNull Class<T> clazz) Gets theSerializerassociated with the specified class.booleanisFrozen()Checks if thisSerializerRegistryis 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) RegistersSerializers 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
SerializerRegistryis frozen.- Type Parameters:
S- a type of objects after serializing- Returns:
- an empty
SerializerRegistry
-
get
Gets theSerializerassociated with the specified class.- Type Parameters:
T- a type of object to serialize- Parameters:
clazz- the class to getSerializer- Returns:
- the
Serializerassociated with the specified class, ornull
-
getAsOptional
@NotNull default <T> @NotNull Optional<Serializer<T,S>> getAsOptional(@NotNull @NotNull Class<T> clazz) Gets theSerializerassociated with the specified class.- Type Parameters:
T- a type of object to serialize- Parameters:
clazz- the class to getSerializer- Returns:
- the
Serializerassociated 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 associateSerializerwithserializer- aSerializerto register- Returns:
- this
SerializerRegistryinstance
-
registerAll
@Contract("_ -> this") @NotNull @NotNull SerializerRegistry<S> registerAll(@NotNull @NotNull SerializerRegistry<S> registry) RegistersSerializers in the givenSerializerRegistry.- Parameters:
registry- aSerializerRegistrythat containsSerializers to register- Returns:
- this
SerializerRegistryinstance
-
freeze
Freezes thisSerializerRegistry.After calling this method,
register(Class, Serializer)andregisterAll(SerializerRegistry)will throwIllegalStateException.This method can be called multiple times.
- Returns:
- this
SerializerRegistryinstance
-
isFrozen
boolean isFrozen()Checks if thisSerializerRegistryis frozen.- Returns:
trueif thisSerializerRegistryis frozen, otherwisefalse
-