Package name.martingeisse.grumpyjson
Record Class JsonRegistries
java.lang.Object
java.lang.Record
name.martingeisse.grumpyjson.JsonRegistries
- Record Components:
serializerRegistry- the serializer registrydeserializerRegistry- the deserializer registry
- All Implemented Interfaces:
JsonDeserializerProvider,JsonProviders,JsonSerializerProvider
public record JsonRegistries(JsonSerializerRegistry serializerRegistry, JsonDeserializerRegistry deserializerRegistry)
extends Record
implements JsonProviders
Groups the
JsonSerializerRegistry and JsonDeserializerRegistry together. These two classes are
separate mostly because it simplifies their implementation, but when using them, the distinction is not useful in
most cases. Code that wants to use them and not make the distinction should instead use this class.-
Constructor Summary
ConstructorsConstructorDescriptionJsonRegistries(JsonSerializerRegistry serializerRegistry, JsonDeserializerRegistry deserializerRegistry) Creates an instance of aJsonRegistriesrecord class. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Removes all registered converters from both registries.static JsonRegistriesCreates a default serializer/deserializer registry pair with built-in auto-generation for record converters.Returns the value of thedeserializerRegistryrecord component.final booleanIndicates whether some other object is "equal to" this one.getDeserializer(Type type) Returns a registered deserializer for the specified type, auto-generating it if necessary and possible.<T> JsonSerializer<T>getSerializer(Class<T> clazz) Returns a registered serializer for the specified class, auto-generating it if necessary and possible.final inthashCode()Returns a hash code value for this object.voidregisterDeserializer(JsonDeserializer deserializer) Registers the specified deserializer.<T extends JsonSerializer<?> & JsonDeserializer>
voidregisterDualConverter(T converter) Registers the specified dual converter.voidregisterSerializer(JsonSerializer<?> serializer) Registers the specified serializer.voidseal()Seals the registries, moving from the configuration phase to the run-time phase.Returns the value of theserializerRegistryrecord component.booleansupportsClassForSerialization(Class<?> clazz) Checks whether the specified class is supported for serialization by any serializer that is known to this provider.booleanChecks whether the specified type is supported for deserialization by any deserializer that is known to this provider.final StringtoString()Returns a string representation of this record class.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface name.martingeisse.grumpyjson.deserialize.JsonDeserializerProvider
deserialize, deserializeAbsentMethods inherited from interface name.martingeisse.grumpyjson.serialize.JsonSerializerProvider
serialize, serializeOptional
-
Constructor Details
-
JsonRegistries
public JsonRegistries(JsonSerializerRegistry serializerRegistry, JsonDeserializerRegistry deserializerRegistry) Creates an instance of aJsonRegistriesrecord class.- Parameters:
serializerRegistry- the value for theserializerRegistryrecord componentdeserializerRegistry- the value for thedeserializerRegistryrecord component
-
-
Method Details
-
createDefault
Creates a default serializer/deserializer registry pair with built-in auto-generation for record converters.- Returns:
- the registries
-
registerSerializer
Registers the specified serializer.- Parameters:
serializer- the serializer to register
-
registerDeserializer
Registers the specified deserializer.- Parameters:
deserializer- the deserializer to register
-
registerDualConverter
Registers the specified dual converter.- Type Parameters:
T- the dual converter type which must implement bothJsonSerializerandJsonDeserializer- Parameters:
converter- the dual converter to register
-
clear
public void clear()Removes all registered converters from both registries. This is useful because the registries used by grumpyjson contain default converters, and the code using it might not want to use them. -
supportsClassForSerialization
Description copied from interface:JsonSerializerProviderChecks whether the specified class is supported for serialization by any serializer that is known to this provider. Since this provider usually abstracts aJsonSerializerRegistry, this includes serializers that can be auto-generated on the fly.Note that there are some reasons why a registered serializer may claim to support a class, but fail at run-time when it actually encounters that class. Such a class will still be "supported" by that serializer from the point-of-view of this provider. Refer to the documentation of the individual serializers for details.
- Specified by:
supportsClassForSerializationin interfaceJsonSerializerProvider- Parameters:
clazz- the class to check- Returns:
- true if supported, false if not
-
getSerializer
Description copied from interface:JsonSerializerProviderReturns a registered serializer for the specified class, auto-generating it if necessary and possible. This method will throw an exception if no serializer was registered manually that supports the class and no serializer can be auto-generated. If multiple serializers have been registered that can handle the specified class, the one registered later will take precedence.- Specified by:
getSerializerin interfaceJsonSerializerProvider- Type Parameters:
T- the static type of the class to serialize- Parameters:
clazz- the class to return a serializer for- Returns:
- the registered serializer, possibly auto-generated
- Throws:
NotRegisteredException- if the class is not known to this provider
-
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
-
seal
public void seal()Seals the registries, moving from the configuration phase to the run-time phase. -
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
serializerRegistry
Returns the value of theserializerRegistryrecord component.- Returns:
- the value of the
serializerRegistryrecord component
-
deserializerRegistry
Returns the value of thedeserializerRegistryrecord component.- Returns:
- the value of the
deserializerRegistryrecord component
-