YAML conversion to JSON with Jackson: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 6: Line 6:
<syntaxhighlight lang='java'>
<syntaxhighlight lang='java'>
String convertYamlToJson(String yaml) {
String convertYamlToJson(String yaml) {
     ObjectMapper yamlReader = new ObjectMapper(new YAMLFactory());
     ObjectMapper yamlReader = new ObjectMapper(new YAMLFactory());
     Object obj = yamlReader.readValue(yaml, Object.class);
     Object obj = yamlReader.readValue(yaml, Object.class);

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);
}