Search in sources :

Example 1 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();
    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.getBackend() != null) {
        Backend backend = new Backend(CliConfig.getBackendClass(cliConfig.getBackend()).newInstance());
        ObjectNode backendNode = (ObjectNode) objectMapper.valueToTree(backend);
        configNode.set("backend", backendNode);
    }
    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 : Backend(com.torodb.stampede.config.model.backend.Backend) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) YAMLMapper(com.fasterxml.jackson.dataformat.yaml.YAMLMapper) Config(com.torodb.stampede.config.model.Config) InputStream(java.io.InputStream) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with YAMLMapper

use of com.fasterxml.jackson.dataformat.yaml.YAMLMapper in project cuba by cuba-platform.

the class DocumentationController method getProjectSwaggerYaml.

@RequestMapping(value = "/swaggerDetailed.yaml", method = RequestMethod.GET, produces = "application/yaml")
public String getProjectSwaggerYaml() {
    ObjectMapper jsonWriter = new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL);
    YAMLMapper yamlMapper = new YAMLMapper().disable(WRITE_DOC_START_MARKER);
    try {
        Swagger swagger = swaggerGenerator.generateSwagger();
        JsonNode jsonNode = jsonWriter.readTree(jsonWriter.writeValueAsBytes(swagger));
        return yamlMapper.writeValueAsString(jsonNode);
    } catch (IOException e) {
        throw new RestAPIException("An error occurred while generating Swagger documentation", e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
    }
}
Also used : YAMLMapper(com.fasterxml.jackson.dataformat.yaml.YAMLMapper) Swagger(io.swagger.models.Swagger) RestAPIException(com.haulmont.restapi.exception.RestAPIException) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with YAMLMapper

use of com.fasterxml.jackson.dataformat.yaml.YAMLMapper in project strimzi by strimzi.

the class StrimziRunner method getContent.

String getContent(File file, Consumer<JsonNode> edit) {
    YAMLMapper mapper = new YAMLMapper();
    try {
        JsonNode node = mapper.readTree(file);
        edit.accept(node);
        return mapper.writeValueAsString(node);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : YAMLMapper(com.fasterxml.jackson.dataformat.yaml.YAMLMapper) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException)

Example 4 with YAMLMapper

use of com.fasterxml.jackson.dataformat.yaml.YAMLMapper in project strimzi by strimzi.

the class KafkaClusterTest method replaceCm.

private void replaceCm(String cmName, String fieldName, String fieldValue) {
    try {
        String jsonString = kubeClient.get("cm", cmName);
        YAMLMapper mapper = new YAMLMapper();
        JsonNode node = mapper.readTree(jsonString);
        ((ObjectNode) node.get("data")).put(fieldName, fieldValue);
        String content = mapper.writeValueAsString(node);
        kubeClient.replaceContent(content);
        LOGGER.info("Value in Config Map replaced");
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) YAMLMapper(com.fasterxml.jackson.dataformat.yaml.YAMLMapper) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException)

Example 5 with YAMLMapper

use of com.fasterxml.jackson.dataformat.yaml.YAMLMapper in project streamline by hortonworks.

the class ConfigFileWriterTest method writeYamlConfigToFile.

@Test
public void writeYamlConfigToFile() throws Exception {
    Map<String, String> configuration = createDummyConfiguration();
    File destPath = Files.createTempFile("config", "yaml").toFile();
    destPath.deleteOnExit();
    writer.writeConfigToFile(ConfigFileType.YAML, configuration, destPath);
    assertTrue(destPath.exists());
    try (InputStream is = new FileInputStream(destPath)) {
        String content = IOUtils.toString(is);
        System.out.println("Test print: yaml content - " + content);
        ObjectMapper mapper = new YAMLMapper();
        Map<String, Object> readConfig = mapper.readValue(content, Map.class);
        assertEquals(configuration, readConfig);
    }
}
Also used : YAMLMapper(com.fasterxml.jackson.dataformat.yaml.YAMLMapper) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) File(java.io.File) FileInputStream(java.io.FileInputStream) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

YAMLMapper (com.fasterxml.jackson.dataformat.yaml.YAMLMapper)18 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)12 IOException (java.io.IOException)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)6 InputStream (java.io.InputStream)5 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)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 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectReader (com.fasterxml.jackson.databind.ObjectReader)1