Class JsonDeserializerRegistry

All Implemented Interfaces:
JsonDeserializerProvider

public final class JsonDeserializerRegistry extends Registry<Type,JsonDeserializer> implements JsonDeserializerProvider
This registry keeps the JsonDeserializers used by a JsonEngine.
  • Constructor Details

    • JsonDeserializerRegistry

      public JsonDeserializerRegistry(RecordConverterFactory recordConverterFactory)
      NOT PUBLIC API
      Parameters:
      recordConverterFactory - ...
  • Method Details

    • registrableSupports

      protected boolean registrableSupports(JsonDeserializer registrable, Type key)
      Description copied from class: Registry
      Checks whether the specified registrable supports the specified key.

      This method must always return the same result for the same registrable and key.

      Specified by:
      registrableSupports in class Registry<Type,JsonDeserializer>
      Parameters:
      registrable - the registrable which is checked for the key
      key - the key to check
      Returns:
      true if the registrable supports the key, false if not
    • generateRegistrable

      protected JsonDeserializer generateRegistrable(Type type)
      Description copied from class: Registry
      Auto-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:
      generateRegistrable in class Registry<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

      protected String getErrorMessageForUnknownKey(Type type)
      Description copied from class: Registry
      Produces 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:
      getErrorMessageForUnknownKey in class Registry<Type,JsonDeserializer>
      Parameters:
      type - the unknown key
      Returns:
      the error message
    • supportsTypeForDeserialization

      public boolean supportsTypeForDeserialization(Type type)
      Description copied from interface: JsonDeserializerProvider
      Checks whether the specified type is supported for deserialization by any deserializer that is known to this provider. Since this provider usually abstracts a JsonDeserializerRegistry, 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:
      supportsTypeForDeserialization in interface JsonDeserializerProvider
      Parameters:
      type - the type to check
      Returns:
      true if supported, false if not
    • getDeserializer

      public JsonDeserializer getDeserializer(Type type) throws NotRegisteredException
      Description copied from interface: JsonDeserializerProvider
      Returns 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:
      getDeserializer in interface JsonDeserializerProvider
      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