YAML conversion to JSON with Jackson

From NovaOrdis Knowledge Base
Jump to navigation Jump to search

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