Package me.hsgamer.hscore.serializer
Class Serializer<I,O>
java.lang.Object
me.hsgamer.hscore.serializer.Serializer<I,O>
- Type Parameters:
I
- the type of the input objectO
- the type of the output object
The serializer
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptiondeserialize
(String type, I input) Deserialize the inputGet the registered types<T extends O>
Serializer<I,O> Register a new entry, without specifying the type and the input function.<T extends O>
Serializer<I,O> Register a new entry, without specifying the type.<T extends O>
Serializer<I,O> register
(String type, Class<T> outputClass, Function<I, T> outputFunction, Function<T, I> inputFunction) Register a new entrySerialize the outputSerializer<I,
O> unregister
(Class<? extends O> outputClass) Unregister an entrySerializer<I,
O> unregister
(String type) Unregister an entry
-
Constructor Details
-
Serializer
public Serializer()
-
-
Method Details
-
register
public <T extends O> Serializer<I,O> register(String type, Class<T> outputClass, Function<I, T> outputFunction, Function<T, I> inputFunction) Register a new entry- Type Parameters:
T
- the type of the output- Parameters:
type
- the typeoutputClass
- the class of the outputoutputFunction
- the output functioninputFunction
- the input function- Returns:
- the serializer
- Throws:
IllegalArgumentException
- if the type or the class is already registered
-
register
public <T extends O> Serializer<I,O> register(Class<T> outputClass, Function<I, T> outputFunction, Function<T, I> inputFunction) Register a new entry, without specifying the type. The type will be the class name of the output, or the value ofSerializerType
if the class is annotated with it.- Type Parameters:
T
- the type of the output- Parameters:
outputClass
- the class of the outputoutputFunction
- the output functioninputFunction
- the input function- Returns:
- the serializer
-
register
Register a new entry, without specifying the type and the input function. The type will be the class name of the output, or the value ofSerializerType
if the class is annotated with it. The input function will be the method annotated withSerializerInputFunction
in the output class, which must be public and non-static. The output function will be the method annotated withSerializerOutputFunction
in the output class, which must be public and static.- Type Parameters:
T
- the type of the output- Parameters:
outputClass
- the class of the output- Returns:
- the serializer
- Throws:
IllegalArgumentException
- if the output class does not have the required methods
-
unregister
Unregister an entry- Parameters:
type
- the type- Returns:
- the serializer
-
unregister
Unregister an entry- Parameters:
outputClass
- the class of the output- Returns:
- the serializer
-
deserialize
Deserialize the input- Parameters:
type
- the typeinput
- the input- Returns:
- the output
-
serialize
Serialize the output- Parameters:
output
- the output- Returns:
- the entry of the type and the input
-
getRegisteredTypes
Get the registered types- Returns:
- the registered types
-