Class TypeSerializerCollection.Builder
- java.lang.Object
-
- org.spongepowered.configurate.serialize.TypeSerializerCollection.Builder
-
- Enclosing class:
- TypeSerializerCollection
public static class TypeSerializerCollection.Builder extends Object
A builder to construct new serializer collections.Serializers added to a builder will be prioritized based on registration order, so if multiple serializers could match a single type, the first-registered one will be used.
- Since:
- 4.0.0
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TypeSerializerCollectionbuild()Create a new type serializer collection.<T> TypeSerializerCollection.Builderregister(TypeToken<T> type, TypeSerializer<? super T> serializer)Register a type serializer for a given type.<T> TypeSerializerCollection.Builderregister(Class<T> type, TypeSerializer<? super T> serializer)Register a type serializer for a given type.<T> TypeSerializerCollection.Builderregister(Predicate<Type> test, TypeSerializer<? super T> serializer)Register a type serializer matching against a given predicate.<T> TypeSerializerCollection.Builderregister(ScalarSerializer<T> serializer)Register a scalar serializer with its own attached type token.TypeSerializerCollection.BuilderregisterAll(TypeSerializerCollection other)Register all serializers fromotherinto this collection.TypeSerializerCollection.BuilderregisterAnnotatedObjects(ObjectMapper.Factory factory)Register a customized object mapper to handleConfigSerializable-annotated objects.<T> TypeSerializerCollection.BuilderregisterExact(TypeToken<T> type, TypeSerializer<? super T> serializer)Register an exact type serializer for a given type.<T> TypeSerializerCollection.BuilderregisterExact(Class<T> type, TypeSerializer<? super T> serializer)Register an exact type serializer for a given type.<T> TypeSerializerCollection.BuilderregisterExact(ScalarSerializer<T> serializer)Register a scalar serializer with its own attached type token.
-
-
-
Method Detail
-
register
public <T> TypeSerializerCollection.Builder register(TypeToken<T> type, TypeSerializer<? super T> serializer)
Register a type serializer for a given type.Serializers registered will match all subclasses of the provided type, as well as unwrapped primitive equivalents of the type.
- Type Parameters:
T- the type to generify around- Parameters:
type- the type to acceptserializer- the serializer that will be serialized with- Returns:
- this builder
- Since:
- 4.0.0
-
register
public <T> TypeSerializerCollection.Builder register(Class<T> type, TypeSerializer<? super T> serializer)
Register a type serializer for a given type.Serializers registered will match all subclasses of the provided type, as well as unboxed primitive equivalents of the type.
- Type Parameters:
T- the type to generify around- Parameters:
type- the type to acceptserializer- the serializer that will be serialized with- Returns:
- this builder
- Since:
- 4.0.0
-
register
public <T> TypeSerializerCollection.Builder register(Predicate<Type> test, TypeSerializer<? super T> serializer)
Register a type serializer matching against a given predicate.- Type Parameters:
T- the type parameter- Parameters:
test- the predicate to match types againstserializer- the serializer to serialize matching types with- Returns:
- this builder
- Since:
- 4.0.0
-
register
public <T> TypeSerializerCollection.Builder register(ScalarSerializer<T> serializer)
Register a scalar serializer with its own attached type token.Serializers registered will match all subclasses of the provided type, as well as unboxed primitive equivalents of the type.
- Type Parameters:
T- value type- Parameters:
serializer- serializer to register- Returns:
- this builder
- Since:
- 4.0.0
-
registerExact
public <T> TypeSerializerCollection.Builder registerExact(TypeToken<T> type, TypeSerializer<? super T> serializer)
Register an exact type serializer for a given type.Serializers will only match exact object types. For example, a serializer registered for
List<String>would not match whenArrayList<String>is queried.- Type Parameters:
T- the type to generify around- Parameters:
type- the type to acceptserializer- the serializer that will be serialized with- Returns:
- this builder
- Since:
- 4.0.0
-
registerExact
public <T> TypeSerializerCollection.Builder registerExact(Class<T> type, TypeSerializer<? super T> serializer)
Register an exact type serializer for a given type.Serializers will only match exact object types. For example, a serializer registered for
List<String>would not match whenArrayList<String>is queried.- Type Parameters:
T- the type to generify around- Parameters:
type- the type to acceptserializer- the serializer that will be serialized with- Returns:
- this builder
- Since:
- 4.0.0
-
registerExact
public <T> TypeSerializerCollection.Builder registerExact(ScalarSerializer<T> serializer)
Register a scalar serializer with its own attached type token.Serializers will only match exact object types. For example, a serializer registered for
List<String>would not match whenArrayList<String>is queried.- Type Parameters:
T- value type- Parameters:
serializer- serializer to register- Returns:
- this builder
- Since:
- 4.0.0
-
registerAll
public TypeSerializerCollection.Builder registerAll(TypeSerializerCollection other)
Register all serializers fromotherinto this collection.Creating a child collection should be preferred, but when merging multiple sets of serializers together, directly adding other collections may be the best choice.
- Parameters:
other- source collection- Returns:
- this builder
- Since:
- 4.0.0
-
registerAnnotatedObjects
public TypeSerializerCollection.Builder registerAnnotatedObjects(ObjectMapper.Factory factory)
Register a customized object mapper to handleConfigSerializable-annotated objects.- Parameters:
factory- factory to retrieve object mappers from- Returns:
- this builder
- Since:
- 4.0.0
-
build
public TypeSerializerCollection build()
Create a new type serializer collection.- Returns:
- a newly created collection
- Since:
- 4.0.0
-
-