use of com.fasterxml.jackson.dataformat.yaml.YAMLMapper in project carbon-apimgt by wso2.
the class CommonUtil method jsonToYaml.
/**
* Converts JSON to YAML.
*
* @param json json representation
* @return json file as a yaml document
* @throws IOException If an error occurs while converting JSON to YAML
*/
public static String jsonToYaml(String json) throws IOException {
ObjectMapper yamlReader = new ObjectMapper(new YAMLFactory().enable(JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER));
JsonNode jsonNodeTree = yamlReader.readTree(json);
YAMLMapper yamlMapper = new YAMLMapper().disable(YAMLGenerator.Feature.SPLIT_LINES).enable(YAMLGenerator.Feature.INDENT_ARRAYS).disable(YAMLGenerator.Feature.LITERAL_BLOCK_STYLE).disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER).enable(YAMLGenerator.Feature.MINIMIZE_QUOTES).enable(YAMLGenerator.Feature.ALWAYS_QUOTE_NUMBERS_AS_STRINGS);
return yamlMapper.writeValueAsString(jsonNodeTree);
}
use of com.fasterxml.jackson.dataformat.yaml.YAMLMapper in project logging-log4j2 by apache.
the class StackTraceElementYamlMixInTest method testFromYamlWithSimpleModule.
@Test
public void testFromYamlWithSimpleModule() throws Exception {
final ObjectMapper mapper = new YAMLMapper();
final SimpleModule module = new SimpleModule();
module.addDeserializer(StackTraceElement.class, new Log4jStackTraceElementDeserializer());
mapper.registerModule(module);
final StackTraceElement expected = new StackTraceElement("package.SomeClass", "someMethod", "SomeClass.java", 123);
final StackTraceElement actual = mapper.readValue("---\nclass: package.SomeClass\nmethod: someMethod\nfile: SomeClass.java\nline: 123\n...", StackTraceElement.class);
Assert.assertEquals(expected, actual);
}
use of com.fasterxml.jackson.dataformat.yaml.YAMLMapper in project fess by codelibs.
the class PluginHelper method loadArtifactsFromRepository.
protected List<Artifact> loadArtifactsFromRepository(final String url) {
final String content = getRepositoryContent(url);
final ObjectMapper objectMapper = new YAMLMapper();
try {
@SuppressWarnings("unchecked") final List<Map<?, ?>> result = objectMapper.readValue(content, List.class);
if (result != null) {
return result.stream().map(o -> new Artifact((String) o.get("name"), (String) o.get("version"), (String) o.get("url"))).collect(Collectors.toList());
}
return Collections.emptyList();
} catch (final Exception e) {
throw new PluginException("Failed to access " + url, e);
}
}
Aggregations