Class ConfigSerializer
Utility class for serializing objects with control via annotations
The two annotations used by this serializer are SerializableField and ExcludeField
To exclude a field from serialization, annotate it with ExcludeField
To make a field be serialized further, annotate it with SerializableField
You can define flags and flag groups to change when fields can be serialized
IMPORTANT: You should exclude any fields that have two-way pointers (I.E. a child element that has its parent as a field when its parent has the child as a field). If you don't, you will likely get a StackOverflowException when serializing! If you need the references, exclude only the child so that when you serialize the parent, it will still serialize the child but not cause the problem.
Also, primitive arrays such as int[] give the config problems. Where possible, use array lists instead for better compatibility.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voiddefineFlag(String name) Defines a new flag for field exclusionstatic voiddefineFlagGroup(String name, String... members) Defines a new flag group for field exclusionstatic voidSerializes an object excluding fields with any exclude annotationsstatic voidSerializes an object excluding fields that match the provided exclude flag
-
Field Details
-
ALL_FLAG
- See Also:
-
-
Constructor Details
-
ConfigSerializer
public ConfigSerializer()
-
-
Method Details
-
defineFlag
Defines a new flag for field exclusion- Parameters:
name- flag name
-
defineFlagGroup
Defines a new flag group for field exclusion- Parameters:
name- flag namemembers- names of flags to include in the group
-
serialize
Serializes an object excluding fields with any exclude annotations- Parameters:
obj- object to serializeconfig- config to serialize to
-
serialize
public static void serialize(Object obj, org.bukkit.configuration.ConfigurationSection config, String flag) Serializes an object excluding fields that match the provided exclude flag
Matching a flag requires the two flags to share any flag. This means that two flag groups will match if at least one of their children match and two regular flags will match only when they are the same.
- Parameters:
obj- object to serializeconfig- config to serialize intoflag- flag name
-