This is based on Ortus's version, but this returns native CFML arrays/structs.
Last active
May 18, 2023 01:40
-
-
Save jamiejackson/a8ecb38d47abd40e5143940b7e5a8916 to your computer and use it in GitHub Desktop.
Read/Write YAML from CFML (Lucee & Adobe ColdFusion)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| component { | |
| public any function init() { | |
| _setupYamlParser(); | |
| return this; | |
| } | |
| public any function YAMLToCFML( required string yaml ) { | |
| var results = _getYamlParser().load( arguments.yaml ); | |
| return deserializeJSON(serializeJSON(results)) ?: {}; | |
| } | |
| public any function CFMLToYAML( required any data ) { | |
| return _getYamlParser().dump( arguments.data ); | |
| } | |
| // PRIVATE | |
| private void function _setupYamlParser() { | |
| var javaLib = [ "/app/lib/yamlparser/snakeyaml.jar" ]; | |
| var parser = CreateObject( "java", "org.yaml.snakeyaml.Yaml", javaLib ).init(); | |
| _setYamlParser( parser ); | |
| } | |
| private any function _getYamlParser() output=false { | |
| return _yamlParser; | |
| } | |
| private void function _setYamlParser( required any yamlParser ) output=false { | |
| _yamlParser = arguments.yamlParser; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment