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