Yaml
Last updated
Was this helpful?
Last updated
Was this helpful?
This module provides a YAML parser and emitter for BoxLang. It is based on the library and provides a simple way to parse and emit YAML content in BoxLang.
This module registers the following BIFS:
yamlSerialize( content, [filepath], [charset=utf8] ):yaml
: Serialize a BoxLang variable into a YAML string. You can also serialize to a file if you provide a file path.
yamlDeserialize( content ):any
: Deserialize a YAML string into a BoxLang variable.
yamlDeserializeFile( filepath, [charset=utf8] ):any
: Deserialize a YAML file into a BoxLang variable.
Here is a simple example:
BoxLang classes will be serialized as a structure according to its properties. However it must adhere to the following rules:
The class must have a serializable = true
annotation. or none at all, that is the default.
The property must have a serializable = true
annotation or none at all, that is the default.
The property must NOT exist in the yamlExclude
list in the class or the parent class.
The property must NOT have a yamlExclude
annotation.
If you are serializing BoxLang classes, you can implement the toYAML()
method in your classes to provide a custom serialization. Here is an example: