Class SerializerFactory

java.lang.Object
dev.crafty.core.config.serializer.SerializerFactory

public class SerializerFactory extends Object
Factory for creating serializers for common types. This class provides methods for creating serializers for primitive types and other common Java types.
Since:
1.0.0
  • Constructor Details

    • SerializerFactory

      public SerializerFactory()
  • Method Details

    • createSimpleSerializer

      public static <T> ConfigSerializer<T> createSimpleSerializer(Class<T> type, BiFunction<SectionWrapper,String,Optional<T>> getter)
      Create a serializer for a primitive type or other simple type that can be directly stored in a configuration section.
      Type Parameters:
      T - The type to create a serializer for
      Parameters:
      type - The class of the type to create a serializer for
      getter - The function to get the value from the configuration section
      Returns:
      A serializer for the specified type
    • createListSerializer

      public static <T> ConfigSerializer<List<T>> createListSerializer(Class<List<T>> type, Class<T> itemType, BiFunction<SectionWrapper,String,Optional<List<T>>> getter)
      Create a serializer for a list of items.
      Type Parameters:
      T - The type of the items in the list
      Parameters:
      type - The class of the list type
      itemType - The class of the items in the list
      getter - The function to get the list from the configuration section
      Returns:
      A serializer for the specified list type
    • registerBuiltInSerializers

      public static void registerBuiltInSerializers()
      Register all the built-in serializers. This method should be called when the plugin is enabled.