Skip to content
zml edited this page May 10, 2020 · 4 revisions

Type serializers are Configurate's mechanism for converting between types native to each configuration format and what is requested by a user. Configurate comes with a library of serializers that cover many common classes in the JDK. These are:

  • java.net.URI
  • java.net.URL
  • java.util.UUID -- supporting UUIDs in both RFC and Mojang (without dashes) formats
  • Any class annotated with @ConfigSerializable -- processed through the Object Mapper
  • byte, short, int, long, float, and double numbers,
  • char
  • boolean
  • java.lang.String
  • java.util.Map -- Instances will be created using the MapFactory set on the configuration options
  • java.util.List -- deserialized values are currently instances of ArrayList
  • Any enum class
  • java.util.regex.Pattern
  • Any type of array -- primitive and Object[]
  • java.util.Set -- deserialized values are currently instances of HashSet
  • ConfigurationNode -- the underlying node will be copied.

Registering type serializers

To be able to locate type serializers, they have to be registered for specific types. Standard serializers are included in the default collection, accessible at TypeSerializerCollection.defaults(). While it is possible to register type serializers in the global collection, as of v3.7 that behaviour is deprecated, and will be removed entirely for 4.0. Instead, it is preferred to register custom serializers in a child collection of the global defaults.

Creating a custom type serializer

While Configurate's stock serializers and object mappers should be the first choices for converting objects, sometimes it is necessary to perform custom serialization. In that case, custom implementations of TypeSerializer can be created.

TODO: Mention AbstractListChildSerializer and ScalarSerializer as useful base classes

Reference https://docs.spongepowered.org/stable/en/plugin/configuration/serialization.html#creating-a-custom-typeserializer for an example while this documentation is created.

Clone this wiki locally