public class TextTemplateConfigSerializer extends Object implements ninja.leaping.configurate.objectmapping.serialize.TypeSerializer<TextTemplate>
TypeSerializer
for TextTemplate
s. TextTemplates
are serialized in two parts.
First, the template's arguments as defined by
TextTemplate.getArguments()
are serialized to the "arguments" node.
This is where the argument definitions are kept.
Second, the template's text representation as defined by
TextTemplate.toText()
is serialized to the "content" node.
Deserialization is a bit more complicated. We start by loading the
"content" Text and check the root Text element as well as it's children. If
a LiteralText
value is found that is wrapped in curly braces we
check to see if the value inside the braces is defined as an argument in the
"arguments" nodes. If so, we use the name and format from the original
LiteralText and obtain whether the argument is optional from the definition.
This is repeated until there are no more Text children to check and we
return a TextTemplate of the elements we have collected.
Constructor and Description |
---|
TextTemplateConfigSerializer() |
Modifier and Type | Method and Description |
---|---|
TextTemplate |
deserialize(TypeToken<?> type,
ninja.leaping.configurate.ConfigurationNode value) |
void |
serialize(TypeToken<?> type,
TextTemplate obj,
ninja.leaping.configurate.ConfigurationNode value) |
public TextTemplate deserialize(TypeToken<?> type, ninja.leaping.configurate.ConfigurationNode value) throws ninja.leaping.configurate.objectmapping.ObjectMappingException
deserialize
in interface ninja.leaping.configurate.objectmapping.serialize.TypeSerializer<TextTemplate>
ninja.leaping.configurate.objectmapping.ObjectMappingException
public void serialize(TypeToken<?> type, TextTemplate obj, ninja.leaping.configurate.ConfigurationNode value) throws ninja.leaping.configurate.objectmapping.ObjectMappingException
serialize
in interface ninja.leaping.configurate.objectmapping.serialize.TypeSerializer<TextTemplate>
ninja.leaping.configurate.objectmapping.ObjectMappingException