-
Notifications
You must be signed in to change notification settings - Fork 8
Serialization
Ridan Vandenbergh edited this page Mar 22, 2020
·
1 revision
Fiber separates serialization and the IR tree, allowing you to convert back and forth from practically any format. By default, fiber comes with Jankson, which is a JSON superset that allows comments.
Let's start off by creating a dummy IR:
@Settings(namingConvention = UnderscoredLowerCaseConvention.class)
private static class MyConfiguration {
private int fooBar = 5;
@Setting.Node
private SubNode node = new SubNode();
public static class SubNode {
private String bazQux = "Hello world!";
}
}
ConfigNode node = new ConfigNode();
AnnotatedSettings.applyToNode(node, new MyConfiguration());
To serialize this IR into a Jankson file, create a JanksonSerializer
:
JanksonSerializer serializer = new JanksonSerializer();
And just call the serialize
method.
serializer.serialize(node, System.out); // note: we're writing to sysout, but this could be a FileOutputStream
This will produce the following output:
{
"foo_bar": 5,
"node": {
"bazQux": "Hello world!"
}
}