YAML conversion to JSON with Jackson: Difference between revisions
Jump to navigation
Jump to search
(One intermediate revision by the same user not shown) | |||
Line 2: | Line 2: | ||
* [[Jackson#Subjects|Jackson]] | * [[Jackson#Subjects|Jackson]] | ||
* [[Conversion between YAML and JSON]] | * [[Conversion between YAML and JSON]] | ||
* [[YAML#YAML_support_in_Java|YAML]] | |||
=Overview= | =Overview= | ||
<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); |
Latest revision as of 23:07, 18 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);
}