Search in sources :

Example 6 with YAMLMapper

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);
}
Also used : Log4jStackTraceElementDeserializer(org.apache.logging.log4j.jackson.Log4jStackTraceElementDeserializer) YAMLMapper(com.fasterxml.jackson.dataformat.yaml.YAMLMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) Test(org.junit.Test)

Example 7 with YAMLMapper

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;
}
Also used : YAMLMapper(com.fasterxml.jackson.dataformat.yaml.YAMLMapper)

Example 8 with 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;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) YAMLMapper(com.fasterxml.jackson.dataformat.yaml.YAMLMapper) Config(com.torodb.standalone.config.model.Config) InputStream(java.io.InputStream) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 9 with YAMLMapper

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;
}
Also used : YAMLMapper(com.fasterxml.jackson.dataformat.yaml.YAMLMapper) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 10 with YAMLMapper

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())));
}
Also used : XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) HashMap(java.util.HashMap) JavaPropsMapper(com.fasterxml.jackson.dataformat.javaprop.JavaPropsMapper) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) JavaPropsSchema(com.fasterxml.jackson.dataformat.javaprop.JavaPropsSchema) YAMLMapper(com.fasterxml.jackson.dataformat.yaml.YAMLMapper) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) TypeReference(com.fasterxml.jackson.core.type.TypeReference) InputStream(java.io.InputStream) YAMLMapper(com.fasterxml.jackson.dataformat.yaml.YAMLMapper) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) TypeReference(com.fasterxml.jackson.core.type.TypeReference) HashMap(java.util.HashMap) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map)

Aggregations

YAMLMapper (com.fasterxml.jackson.dataformat.yaml.YAMLMapper)15 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)10 IOException (java.io.IOException)6 InputStream (java.io.InputStream)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 Map (java.util.Map)2 Test (org.junit.Test)2 MutableDependencyGraph (com.blackducksoftware.integration.hub.bdio.graph.MutableDependencyGraph)1 MutableMapDependencyGraph (com.blackducksoftware.integration.hub.bdio.graph.MutableMapDependencyGraph)1 Dependency (com.blackducksoftware.integration.hub.bdio.model.dependency.Dependency)1 NameVersionNode (com.blackducksoftware.integration.hub.detect.nameversion.NameVersionNode)1 NodeMetadata (com.blackducksoftware.integration.hub.detect.nameversion.NodeMetadata)1 SubcomponentNodeBuilder (com.blackducksoftware.integration.hub.detect.nameversion.builder.SubcomponentNodeBuilder)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectReader (com.fasterxml.jackson.databind.ObjectReader)1