YAML conversion to JSON with Jackson: Difference between revisions
Jump to navigation
Jump to search
Line 4: | Line 4: | ||
=Overview= | =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);
}