use of com.fasterxml.jackson.dataformat.yaml.YAMLMapper in project logging-log4j2 by apache.
the class StackTraceElementYamlMixInTest method testFromYamlWithLog4jModule.
@Test
public void testFromYamlWithLog4jModule() throws Exception {
final ObjectMapper mapper = new YAMLMapper();
final boolean encodeThreadContextAsList = false;
final SimpleModule module = new Log4jYamlModule(encodeThreadContextAsList, true, false);
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 torodb by torodb.
the class ConfigUtils method yamlMapper.
public static YAMLMapper yamlMapper() {
YAMLMapper yamlMapper = new YAMLMapper();
configMapper(yamlMapper);
return yamlMapper;
}
use of com.fasterxml.jackson.dataformat.yaml.YAMLMapper in project torodb by torodb.
the class CliConfigUtils method uncatchedReadConfig.
private static Config uncatchedReadConfig(final CliConfig cliConfig) throws Exception {
ObjectMapper objectMapper = ConfigUtils.mapper();
Config defaultConfig = new Config();
if (cliConfig.getBackend() != null) {
defaultConfig.getBackend().setBackendImplementation(CliConfig.getBackendClass(cliConfig.getBackend()).newInstance());
}
ObjectNode configNode = (ObjectNode) objectMapper.valueToTree(defaultConfig);
if (cliConfig.hasConfFile() || cliConfig.hasXmlConfFile()) {
ObjectMapper mapper = null;
InputStream inputStream = null;
if (cliConfig.hasConfFile()) {
mapper = ConfigUtils.yamlMapper();
inputStream = cliConfig.getConfInputStream();
} else if (cliConfig.hasXmlConfFile()) {
mapper = ConfigUtils.xmlMapper();
inputStream = cliConfig.getXmlConfInputStream();
}
if (inputStream != null) {
Config config = mapper.readValue(inputStream, Config.class);
configNode = mapper.valueToTree(config);
}
}
if (cliConfig.getParams() != null) {
YAMLMapper yamlMapper = ConfigUtils.yamlMapper();
for (String paramPathValue : cliConfig.getParams()) {
int paramPathValueSeparatorIndex = paramPathValue.indexOf('=');
String pathAndProp = paramPathValue.substring(0, paramPathValueSeparatorIndex);
if (pathAndProp.startsWith("/")) {
pathAndProp = pathAndProp.substring(1);
}
pathAndProp = "/" + pathAndProp;
String value = paramPathValue.substring(paramPathValueSeparatorIndex + 1);
configNode = ConfigUtils.mergeParam(yamlMapper, configNode, pathAndProp, value);
}
}
Config config = objectMapper.treeToValue(configNode, Config.class);
validateBean(config);
return config;
}
use of com.fasterxml.jackson.dataformat.yaml.YAMLMapper in project torodb by torodb.
the class ConfigUtils method readConfigFromYaml.
public static <T> T readConfigFromYaml(Class<T> configClass, String yamlString) throws JsonProcessingException, IOException {
ObjectMapper objectMapper = mapper();
YAMLMapper yamlMapper = yamlMapper();
JsonNode configNode = yamlMapper.readTree(yamlString);
T config = objectMapper.treeToValue(configNode, configClass);
validateBean(config);
return config;
}
use of com.fasterxml.jackson.dataformat.yaml.YAMLMapper in project streamline by hortonworks.
the class ConfigFileReader method readConfigFromYamlType.
private Map<String, String> readConfigFromYamlType(InputStream configFileStream) throws IOException {
ObjectReader reader = new YAMLMapper().reader();
Map<String, Object> confMap = reader.forType(new TypeReference<Map<String, Object>>() {
}).readValue(configFileStream);
return confMap.entrySet().stream().collect(toMap(Map.Entry::getKey, e -> convertValueAsString(e.getValue())));
}
Aggregations