BoxLang 🚀 A New JVM Dynamic Language Learn More...
|:------------------------------------------------------: |
| ⚡︎ B o x L a n g ⚡︎
| Dynamic : Modular : Productive
|:------------------------------------------------------: |
Copyright Since 2023 by Ortus Solutions, Corp
www.boxlang.io | www.ortussolutions.com
This module provides a YAML parser and emitter for BoxLang. It is based on the SnakeYAML library and provides a simple way to parse and emit YAML content in BoxLang.
You can install it via the BoxLang CLI:
install-bx-module bx-yaml
Or you can install it into a CommandBox server:
box install boxlang-yaml
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:
// Serialize a BoxLang structure into a YAML string
yaml = yamlSerialize( { name="Luis", age=21, city="Orlando" } );
// Serialize a more complex structure
yaml = yamlSerialize( { name="Luis", age=21, city="Orlando", address={ street="1234", city="Orlando", state="FL" } } );
// Deserialize a YAML string into a BoxLang structure
data = yamlDeserialize( yaml );
// Deserialize a YAML file into a BoxLang structure
data = yamlDeserializeFile( "data.yml" );
BoxLang classes will be serialized as a structure according to its properties. However it must adhere to the following rules:
serializable = true
annotation. or none at all, that is the default.serializable = true
annotation or none at all, that is the default.yamlExclude
list in the class or the parent class.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:
class {
function init( required name="", required age=0, required city="" ){
variables.name = arguments.name;
variables.age = arguments.age;
variables.city = arguments.city;
return this;
}
function toYAML(){
return { name=variables.name, city=variables.city } );
}
}
BoxLang is a professional open-source project and it is completely funded by the community and Ortus Solutions, Corp. Ortus Patreons get many benefits like a cfcasts account, a FORGEBOX Pro account and so much more. If you are interested in becoming a sponsor, please visit our patronage page: https://patreon.com/ortussolutions
"I am the way, and the truth, and the life; no one comes to the Father, but by me (JESUS)" Jn 14:1-12
All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
$
box install bx-yaml