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 TypeMethodDescriptiondefault Objectdeserialize(com.google.gson.JsonElement source, Type type) Convenience method to find a deserializer for the specifiedType, then use it to deserialize theJsonElement.default ObjectdeserializeAbsent(Type type) Convenience method to find a deserializer for the specifiedType, then use it to generate a default value.getDeserializer(Type type) Returns a registered deserializer for the specified type, auto-generating it if necessary and possible.booleanChecks whether the specified type is supported for deserialization by any deserializer that is known to this provider.
-
Method Details
-
supportsTypeForDeserialization
Checks 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.
- Parameters:
type- the type to check- Returns:
- true if supported, false if not
-
getDeserializer
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 specifiedType, then use it to deserialize theJsonElement.- Parameters:
source- the source elementtype- 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 whichsupportsTypeForDeserialization(Type)returns false
-
deserializeAbsent
Convenience method to find a deserializer for the specifiedType, 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 whichsupportsTypeForDeserialization(Type)returns false
-