Class Adapter<Type,Output>
java.lang.Object
org.polyfrost.oneconfig.api.config.v1.serialize.adapter.Adapter<Type,Output>
- Type Parameters:
Type- the type of this adapterOutput- the output type of this adapter, used to avoid unsafe casts for prettier code.
- Direct Known Subclasses:
ColorAdapter,ComplexAdapter
While the Config API is equipped with an automatic deserializer (see
For this reason, the Adapter API exists, where you can create your own custom serializer for an object into a map of "simple" objects and string keys.
ObjectSerializer.serialize(Object, boolean))
It is not perfect, and may produce ugly looking results. For this reason, the Adapter API exists, where you can create your own custom serializer for an object into a map of "simple" objects and string keys.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract Typedeserialize(Output in) Deserialize your object.final booleanDue to Java type erasure, this method is used to get the type of the adapter.Due to Java type erasure, this method is used to get the type of the adapter.final inthashCode()abstract OutputConvert the given object into a serializable form.
-
Constructor Details
-
Adapter
public Adapter()
-
-
Method Details
-
deserialize
Deserialize your object. The form will be identical to what you made in theserialize(Object)method.- Parameters:
in- the object (same as deserialize) to create your object from- Returns:
- the complete object
-
serialize
Convert the given object into a serializable form.
The following types can be returned by this method, and nothing more:- Primitive wrappers (any
Number,Character,Boolean) - A
Stringliteral or any class implementingCharSequence - An
Enum - An array of the above types, including primitives (e.g.
byte[],int[]..) - A
Listof the above types - A
Map<String,Object>of the above types, mapped to Strings, which are used as keys.
Note that 'class' and 'value' are reserved keys and cannot be used. - Lists containing lists or maps containing maps (or lists) are also supported.
- Parameters:
in- the object to serialize
- Primitive wrappers (any
-
getTargetClass
Due to Java type erasure, this method is used to get the type of the adapter.
This is used internally to get what type adapter to use. -
getOutputClass
Due to Java type erasure, this method is used to get the type of the adapter.
This is used internally to get what type adapter to use. -
equals
-
hashCode
public final int hashCode()
-