Interface DeserializerRegistry<S>
- Type Parameters:
S
- a type of objects to deserialize
public sealed interface DeserializerRegistry<S>
A registry that manages
Deserializer
s.
The implementations of this interface are thread-safe.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <S> @NotNull DeserializerRegistry<S>
create()
Creates a newDeserializerRegistry
.static <S> @NotNull DeserializerRegistry<S>
empty()
Returns an emptyDeserializerRegistry
.@NotNull DeserializerRegistry<S>
freeze()
Freezes thisDeserializerRegistry
.<T> @Nullable Deserializer<S,
T> Gets theDeserializer
associated with the specified class.default <T> @NotNull Optional<Deserializer<S,
T>> getAsOptional
(@NotNull Class<T> clazz) Gets theDeserializer
associated with the specified class.boolean
isFrozen()
Checks if thisDeserializerRegistry
is frozen.<T> @NotNull DeserializerRegistry<S>
register
(@NotNull Class<T> clazz, @NotNull Deserializer<? super S, ? extends T> deserializer) RegistersDeserializer
.@NotNull DeserializerRegistry<S>
registerAll
(@NotNull DeserializerRegistry<S> registry) RegistersDeserializer
s in the givenDeserializerRegistry
.
-
Method Details
-
create
Creates a newDeserializerRegistry
.- Type Parameters:
S
- a type of objects to deserialize- Returns:
- a new
DeserializerRegistry
-
empty
Returns an emptyDeserializerRegistry
.The returning
DeserializerRegistry
is frozen.- Type Parameters:
S
- a type of objects to deserialize- Returns:
- an empty
DeserializerRegistry
-
get
Gets theDeserializer
associated with the specified class.- Type Parameters:
T
- a type of object after deserialization- Parameters:
clazz
- the class to getDeserializer
- Returns:
- the
Deserializer
associated with the specified class, ornull
-
getAsOptional
@NotNull default <T> @NotNull Optional<Deserializer<S,T>> getAsOptional(@NotNull @NotNull Class<T> clazz) Gets theDeserializer
associated with the specified class.- Type Parameters:
T
- a type of object after deserialization- Parameters:
clazz
- the class to getDeserializer
- Returns:
- the
Deserializer
associated with the specified class, orOptional.empty()
.
-
register
@Contract("_, _ -> this") @NotNull <T> @NotNull DeserializerRegistry<S> register(@NotNull @NotNull Class<T> clazz, @NotNull @NotNull Deserializer<? super S, ? extends T> deserializer) RegistersDeserializer
.- Type Parameters:
T
- a type of object after deserialization- Parameters:
clazz
- a class to associateDeserializer
withdeserializer
- aDeserializer
to register- Returns:
- this
DeserializerRegistry
instance
-
registerAll
@Contract("_ -> this") @NotNull @NotNull DeserializerRegistry<S> registerAll(@NotNull @NotNull DeserializerRegistry<S> registry) RegistersDeserializer
s in the givenDeserializerRegistry
.- Parameters:
registry
- aDeserializerRegistry
that containsDeserializer
s to register- Returns:
- this
DeserializerRegistry
instance
-
freeze
Freezes thisDeserializerRegistry
.After calling this method,
register(Class, Deserializer)
andregisterAll(DeserializerRegistry)
will throwIllegalStateException
.This method can be called multiple times.
- Returns:
- this
DeserializerRegistry
instance
-
isFrozen
boolean isFrozen()Checks if thisDeserializerRegistry
is frozen.- Returns:
true
if thisDeserializerRegistry
is frozen, otherwisefalse
-