Record Class JsonRegistries

java.lang.Object
java.lang.Record
name.martingeisse.grumpyjson.JsonRegistries
Record Components:
serializerRegistry - the serializer registry
deserializerRegistry - 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 Details

  • Method Details

    • createDefault

      public static JsonRegistries createDefault()
      Creates a default serializer/deserializer registry pair with built-in auto-generation for record converters.
      Returns:
      the registries
    • registerSerializer

      public void registerSerializer(JsonSerializer<?> serializer)
      Registers the specified serializer.
      Parameters:
      serializer - the serializer to register
    • registerDeserializer

      public void registerDeserializer(JsonDeserializer deserializer)
      Registers the specified deserializer.
      Parameters:
      deserializer - the deserializer to register
    • registerDualConverter

      public <T extends JsonSerializer<?> & JsonDeserializer> void registerDualConverter(T converter)
      Registers the specified dual converter.
      Type Parameters:
      T - the dual converter type which must implement both JsonSerializer and JsonDeserializer
      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

      public boolean supportsClassForSerialization(Class<?> clazz)
      Description copied from interface: JsonSerializerProvider
      Checks whether the specified class is supported for serialization by any serializer that is known to this provider. Since this provider usually abstracts a JsonSerializerRegistry, 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:
      supportsClassForSerialization in interface JsonSerializerProvider
      Parameters:
      clazz - the class to check
      Returns:
      true if supported, false if not
    • getSerializer

      public <T> JsonSerializer<T> getSerializer(Class<T> clazz) throws NotRegisteredException
      Description copied from interface: JsonSerializerProvider
      Returns 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:
      getSerializer in interface JsonSerializerProvider
      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

      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
    • seal

      public void seal()
      Seals the registries, moving from the configuration phase to the run-time phase.
    • toString

      public final String 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.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • 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.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • serializerRegistry

      public JsonSerializerRegistry serializerRegistry()
      Returns the value of the serializerRegistry record component.
      Returns:
      the value of the serializerRegistry record component
    • deserializerRegistry

      public JsonDeserializerRegistry deserializerRegistry()
      Returns the value of the deserializerRegistry record component.
      Returns:
      the value of the deserializerRegistry record component