Difference between revisions of "YAML conversion to JSON with Jackson"

From NovaOrdis Knowledge Base
Jump to: navigation, search
(Created page with "=Internal= * Jackson")
 
(Overview)
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
=Internal=
 
=Internal=
 
* [[Jackson#Subjects|Jackson]]
 
* [[Jackson#Subjects|Jackson]]
 +
* [[Conversion between YAML and JSON]]
 +
 +
=Overview=
 +
<syntaxhighlight lang='java'>
 +
String convertYamlToJson(String yaml) {
 +
 +
    ObjectMapper yamlReader = new ObjectMapper(new YAMLFactory());
 +
    Object obj = yamlReader.readValue(yaml, Object.class);
 +
 +
    ObjectMapper jsonWriter = new ObjectMapper();
 +
    return jsonWriter.writeValueAsString(obj);
 +
}
 +
</syntaxhighlight>

Revision as of 01:54, 8 February 2020

Internal

Overview

String convertYamlToJson(String yaml) {

    ObjectMapper yamlReader = new ObjectMapper(new YAMLFactory());
    Object obj = yamlReader.readValue(yaml, Object.class);

    ObjectMapper jsonWriter = new ObjectMapper();
    return jsonWriter.writeValueAsString(obj);
}