Class JsonDeserializerRegistry
- All Implemented Interfaces:
JsonDeserializerProvider
JsonDeserializers used by a JsonEngine.-
Constructor Summary
ConstructorsConstructorDescriptionJsonDeserializerRegistry(RecordConverterFactory recordConverterFactory) NOT PUBLIC API -
Method Summary
Modifier and TypeMethodDescriptionprotected JsonDeserializergenerateRegistrable(Type type) Auto-generates a registrable in a subclass-specific way.getDeserializer(Type type) Returns a registered deserializer for the specified type, auto-generating it if necessary and possible.protected StringProduces an error message that gets used in an exception for an unknown key.protected booleanregistrableSupports(JsonDeserializer registrable, Type key) Checks whether the specified registrable supports the specified key.booleanChecks whether the specified type is supported for deserialization by any deserializer that is known to this provider.Methods inherited from class name.martingeisse.grumpyjson.registry.Registry
clear, get, onSeal, register, supportsMethods inherited from class name.martingeisse.grumpyjson.registry.Sealable
ensureConfigurationPhase, ensureRunTimePhase, sealMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface name.martingeisse.grumpyjson.deserialize.JsonDeserializerProvider
deserialize, deserializeAbsent
-
Constructor Details
-
JsonDeserializerRegistry
NOT PUBLIC API- Parameters:
recordConverterFactory- ...
-
-
Method Details
-
registrableSupports
Description copied from class:RegistryChecks whether the specified registrable supports the specified key.This method must always return the same result for the same registrable and key.
- Specified by:
registrableSupportsin classRegistry<Type,JsonDeserializer> - Parameters:
registrable- the registrable which is checked for the keykey- the key to check- Returns:
- true if the registrable supports the key, false if not
-
generateRegistrable
Description copied from class:RegistryAuto-generates a registrable in a subclass-specific way. This method does not have to check the key for null, nor whether this registry is in the run-time phase.The returned registrable will only be used for the specified key, not for other keys that it might support as well. To re-use a single auto-generated registrable that supports multiple keys for all the keys it supports, the auto-generation itself must return the same registrable for all those keys.
This method must not cause calls to the registry while in progress. In particular, generating a registrable must not query the registry for other registrables to use as dependencies. There are two reasons for this: First, doing so may corrupt the state of this registry or cause deadlock -- the registry is not built to handle that case, simply because it is not needed by any known registrable. Second, doing so may easily cause infinite recursion when requesting the registrable that is already being built.
It is, however, allowed to build a registrable that refers to this registry when being used. Such a registrable can take the registry as a constructor parameter and store it internally -- and not access the registry inside its constructor to comply with the above rule -- and then access the registry at run-time. This is how various registrables act in practice. This turned out to be a more practical solution anyway because these registrables do not have all the required information available in the constructor, but only at run-time.
- Specified by:
generateRegistrablein classRegistry<Type,JsonDeserializer> - Parameters:
type- the key (never null)- Returns:
- the auto-generated registrable, or null if auto-generation is not supported for that key
-
getErrorMessageForUnknownKey
Description copied from class:RegistryProduces an error message that gets used in an exception for an unknown key. The error message is one of the most frequent points of contact between the registry and application code, so it should be as developer-friendly as possible.- Specified by:
getErrorMessageForUnknownKeyin classRegistry<Type,JsonDeserializer> - Parameters:
type- the unknown key- Returns:
- the error message
-
supportsTypeForDeserialization
Description copied from interface:JsonDeserializerProviderChecks whether the specified type is supported for deserialization by any deserializer that is known to this provider. Since this provider usually abstracts aJsonDeserializerRegistry, this includes deserializers that can be auto-generated on the fly.Note that there are some reasons why a registered deserializer may claim to support a type, but fail at run-time when it actually encounters that type. Such a type will still be "supported" by that deserializer from the point-of-view of this provider. Refer to the documentation of the individual deserializers for details.
- Specified by:
supportsTypeForDeserializationin interfaceJsonDeserializerProvider- Parameters:
type- the type to check- Returns:
- true if supported, false if not
-
getDeserializer
Description copied from interface:JsonDeserializerProviderReturns a registered deserializer for the specified type, auto-generating it if necessary and possible. This method will throw an exception if no deserializer was registered manually that supports the type and no deserializer can be auto-generated. If multiple deserializers have been registered that can handle the specified type, the one registered later will take precedence.- Specified by:
getDeserializerin interfaceJsonDeserializerProvider- Parameters:
type- the type to return a deserializer for- Returns:
- the registered deserializer, possibly auto-generated
- Throws:
NotRegisteredException- if the type is not known to this provider
-