Interface JsonDeserializerProvider

All Known Subinterfaces:
JsonProviders
All Known Implementing Classes:
JsonDeserializerRegistry, JsonRegistries

public interface JsonDeserializerProvider
Abstracts the run-time methods from the JsonDeserializerRegistry so that deserializers which have to look up dependencies don't depend on the full registry.
  • Method Summary

    Modifier and Type
    Method
    Description
    default Object
    deserialize(com.google.gson.JsonElement source, Type type)
    Convenience method to find a deserializer for the specified Type, then use it to deserialize the JsonElement.
    default Object
    Convenience method to find a deserializer for the specified Type, then use it to generate a default value.
    Returns a registered deserializer for the specified type, auto-generating it if necessary and possible.
    boolean
    Checks whether the specified type is supported for deserialization by any deserializer that is known to this provider.
  • Method Details

    • supportsTypeForDeserialization

      boolean supportsTypeForDeserialization(Type type)
      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.

      Parameters:
      type - the type to check
      Returns:
      true if supported, false if not
    • getDeserializer

      JsonDeserializer getDeserializer(Type type) throws NotRegisteredException
      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.
      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
    • deserialize

      default Object deserialize(com.google.gson.JsonElement source, Type type) throws JsonDeserializationException
      Convenience method to find a deserializer for the specified Type, then use it to deserialize the JsonElement.
      Parameters:
      source - the source element
      type - the target type to deserialize to
      Returns:
      the deserialized value
      Throws:
      JsonDeserializationException - if the JSON does not match the target type, or if the target type is a type for which supportsTypeForDeserialization(Type) returns false
    • deserializeAbsent

      default Object deserializeAbsent(Type type) throws JsonDeserializationException
      Convenience method to find a deserializer for the specified Type, then use it to generate a default value.
      Parameters:
      type - the target type to deserialize to
      Returns:
      the generated default value
      Throws:
      JsonDeserializationException - if no default value can be generated for the specified type, or if the target type is a type for which supportsTypeForDeserialization(Type) returns false