Interface DeserializerRegistry<S>
- Type Parameters:
S- a type of objects to deserialize
public sealed interface DeserializerRegistry<S>
A registry that manages
Deserializers.
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 theDeserializerassociated with the specified class.default <T> @NotNull Optional<Deserializer<S,T>> getAsOptional(@NotNull Class<T> clazz) Gets theDeserializerassociated with the specified class.booleanisFrozen()Checks if thisDeserializerRegistryis 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) RegistersDeserializers 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
DeserializerRegistryis frozen.- Type Parameters:
S- a type of objects to deserialize- Returns:
- an empty
DeserializerRegistry
-
get
Gets theDeserializerassociated with the specified class.- Type Parameters:
T- a type of object after deserialization- Parameters:
clazz- the class to getDeserializer- Returns:
- the
Deserializerassociated with the specified class, ornull
-
getAsOptional
@NotNull default <T> @NotNull Optional<Deserializer<S,T>> getAsOptional(@NotNull @NotNull Class<T> clazz) Gets theDeserializerassociated with the specified class.- Type Parameters:
T- a type of object after deserialization- Parameters:
clazz- the class to getDeserializer- Returns:
- the
Deserializerassociated 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 associateDeserializerwithdeserializer- aDeserializerto register- Returns:
- this
DeserializerRegistryinstance
-
registerAll
@Contract("_ -> this") @NotNull @NotNull DeserializerRegistry<S> registerAll(@NotNull @NotNull DeserializerRegistry<S> registry) RegistersDeserializers in the givenDeserializerRegistry.- Parameters:
registry- aDeserializerRegistrythat containsDeserializers to register- Returns:
- this
DeserializerRegistryinstance
-
freeze
Freezes thisDeserializerRegistry.After calling this method,
register(Class, Deserializer)andregisterAll(DeserializerRegistry)will throwIllegalStateException.This method can be called multiple times.
- Returns:
- this
DeserializerRegistryinstance
-
isFrozen
boolean isFrozen()Checks if thisDeserializerRegistryis frozen.- Returns:
trueif thisDeserializerRegistryis frozen, otherwisefalse
-