@Override public String dump(final Properties props) { return new Yaml(new DefaultYamlRepresenter()).dumpAsMap(props); } }
@Override public String dump(final Map<String, DataSourceConfiguration> dataSourceConfigurations) { return new Yaml(new DefaultYamlRepresenter()).dumpAsMap( Maps.transformValues(dataSourceConfigurations, new Function<DataSourceConfiguration, YamlDataSourceConfiguration>() { @Override public YamlDataSourceConfiguration apply(final DataSourceConfiguration input) { YamlDataSourceConfiguration result = new YamlDataSourceConfiguration(); result.setDataSourceClassName(input.getDataSourceClassName()); result.setProperties(input.getProperties()); return result; } })); } }
@Override public String dump(final Map<String, Object> configMap) { return new Yaml(new DefaultYamlRepresenter()).dumpAsMap(configMap); } }
@Override public String dump(final MasterSlaveRuleConfiguration masterSlaveRuleConfiguration) { return new Yaml(new DefaultYamlRepresenter()).dumpAsMap(new YamlMasterSlaveRuleConfiguration(masterSlaveRuleConfiguration)); } }
@Override public String dump(final ShardingRuleConfiguration shardingRuleConfiguration) { return new Yaml(new DefaultYamlRepresenter()).dumpAsMap(createYamlShardingRuleConfiguration(shardingRuleConfiguration)); }
@RequestMapping({ "/{label}/{name}-{profiles}.yml", "/{label}/{name}-{profiles}.yaml" }) public ResponseEntity<String> labelledYaml(@PathVariable String name, @PathVariable String profiles, @PathVariable String label, @RequestParam(defaultValue = "true") boolean resolvePlaceholders) throws Exception { validateProfiles(profiles); Environment environment = labelled(name, profiles, label); Map<String, Object> result = convertToMap(environment); if (this.stripDocument && result.size() == 1 && result.keySet().iterator().next().equals("document")) { Object value = result.get("document"); if (value instanceof Collection) { return getSuccess(new Yaml().dumpAs(value, Tag.SEQ, FlowStyle.BLOCK)); } else { return getSuccess(new Yaml().dumpAs(value, Tag.STR, FlowStyle.BLOCK)); } } String yaml = new Yaml().dumpAsMap(result); if (resolvePlaceholders) { yaml = resolvePlaceholders(prepareEnvironment(environment), yaml); } return getSuccess(yaml); }
@Override public String dump(final Authentication authentication) { YamlAuthentication yamlAuthentication = new YamlAuthentication(); yamlAuthentication.setUsername(authentication.getUsername()); yamlAuthentication.setPassword(authentication.getPassword()); return new Yaml(new DefaultYamlRepresenter()).dumpAsMap(yamlAuthentication); } }
Map<String, String> map = new TreeMap<>(); map.put("foo", null); map.put("bar", null); map.put("foo1", null); map.put("bar1", null); Yaml yaml = new Yaml(); String output = yaml.dumpAsMap(map); // yaml.dump(map); System.out.println("---"); System.out.println(output.replace("null", "~"));
@Override protected String createContaining(String filename, Map<String, Object> map) { String yamlStr = yaml.dumpAsMap(map); return createContaining(filename, yamlStr); }
/** * Create typed configuration for heartbeat module out of generic module configuration. * * @param options Module configuration options. * @return typed heartbeat module configuration from a generic one * @throws ConfigurationException in case the provided options are not valid */ public static HeartbeatConfiguration create(Map<String, Object> options) throws ConfigurationException { HeartbeatConfiguration conf = new HeartbeatConfiguration(); Yaml yaml = new Yaml(); String str = yaml.dumpAsMap(options); conf.values = yaml.loadAs(str, HeartbeatConfiguration.Values.class); return conf; }
private InputStream extractProperties(InputStream inputStream) throws IOException { YamlPropertiesLoader yamlPropertiesLoader = new YamlPropertiesLoader(inputStream); Map<String, Object> flattenedProperties = yamlPropertiesLoader.getFlattenedProperties(); Map<String, Object> filteredProperties = flattenedProperties.entrySet().stream() .filter(entry -> entry.getKey().startsWith(PROPERTY_SOURCES_YAML_PREFIX)) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); String yamlDocument = new Yaml().dumpAsMap(filteredProperties); return new ByteArrayInputStream(yamlDocument.getBytes()); }
/** * Create typed configuration for metrics module out of generic module configuration. * * @param options Module configuration options. * @return types request rate module configuration from a generic one * @throws ConfigurationException in case the provided options are not valid */ public static MetricsConfiguration create(Map<String, Object> options) throws ConfigurationException { MetricsConfiguration conf = new MetricsConfiguration(); Yaml yaml = new Yaml(); String str = yaml.dumpAsMap(options); conf.values = yaml.loadAs(str, MetricsConfiguration.Values.class); return conf; }
/** * Create typed configuration for cluster health module out of generic module configuration. * * @param options Module configuration options. * @return typed cluster health module configuration from a generic one * @throws ConfigurationException in case the provided options are not valid */ public static ClusterHealthConfiguration create(Map<String, Object> options) throws ConfigurationException { ClusterHealthConfiguration conf = new ClusterHealthConfiguration(); Yaml yaml = new Yaml(); String str = yaml.dumpAsMap(options); conf.values = yaml.loadAs(str, ClusterHealthConfiguration.Values.class); return conf; }
/** * Dump config map. * * @param configMap config map * @return YAML string */ public static String dumpConfigMap(final Map<String, Object> configMap) { return new Yaml(new DefaultYamlRepresenter()).dumpAsMap(configMap); }
/** * Dump authentication. * * @param authentication authentication * @return YAML string */ public static String dumpAuthentication(final Authentication authentication) { return new Yaml(new DefaultYamlRepresenter()).dumpAsMap(authentication); }
/** * Dump properties configuration. * * @param props props * @return YAML string */ public static String dumpProperties(final Properties props) { return new Yaml(new DefaultYamlRepresenter()).dumpAsMap(props); } }
/** * Dump sharding rule configuration. * * @param shardingRuleConfig sharding rule configuration * @return YAML string */ public static String dumpShardingRuleConfiguration(final ShardingRuleConfiguration shardingRuleConfig) { return new Yaml(new DefaultYamlRepresenter()).dumpAsMap(new YamlShardingRuleConfiguration(shardingRuleConfig)); }
/** * Dump master-slave rule configuration. * * @param masterSlaveRuleConfig master-slave rule configuration * @return YAML string */ public static String dumpMasterSlaveRuleConfiguration(final MasterSlaveRuleConfiguration masterSlaveRuleConfig) { return new Yaml(new DefaultYamlRepresenter()).dumpAsMap(new YamlMasterSlaveRuleConfiguration(masterSlaveRuleConfig)); }
public static String convertToYaml(Object object) { Yaml yaml = new Yaml(new SafeConstructor(), new YamlRepresenter()); return yaml.dumpAsMap(object); }
public void write(final OutputStream os, final ChartIndex index) { try (OutputStreamWriter writer = new OutputStreamWriter(os)) { Yaml yaml = new Yaml(new JodaPropertyConstructor(), setupRepresenter(), new DumperOptions(), new Resolver()); String result = yaml.dumpAsMap(index); writer.write(result); } catch (IOException ex) { log.error("Unable to write to OutputStream for index.yaml", ex); } }