public class TextTemplateConfigSerializer extends Object implements 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,
ConfigurationNode value) |
void |
serialize(TypeToken<?> type,
TextTemplate obj,
ConfigurationNode value) |
public TextTemplate deserialize(TypeToken<?> type, ConfigurationNode value) throws ObjectMappingException
deserialize
in interface TypeSerializer<TextTemplate>
ObjectMappingException
public void serialize(TypeToken<?> type, TextTemplate obj, ConfigurationNode value) throws ObjectMappingException
serialize
in interface TypeSerializer<TextTemplate>
ObjectMappingException