Class SerializerFactory
java.lang.Object
dev.crafty.core.config.serializer.SerializerFactory
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <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.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.static void
Register all the built-in serializers.
-
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 forgetter
- 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 typeitemType
- The class of the items in the listgetter
- 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.
-