gpt4 book ai didi

org.yaml.snakeyaml.Yaml.dumpAsMap()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-18 04:22:40 27 4
gpt4 key购买 nike

本文整理了Java中org.yaml.snakeyaml.Yaml.dumpAsMap()方法的一些代码示例,展示了Yaml.dumpAsMap()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Yaml.dumpAsMap()方法的具体详情如下:
包路径:org.yaml.snakeyaml.Yaml
类名称:Yaml
方法名:dumpAsMap

Yaml.dumpAsMap介绍

[英]Serialize a Java object into a YAML string. Override the default root tag with Tag.MAP.

This method is similar to Yaml.dump(data) except that the root tag for the whole document is replaced with Tag.MAP tag (implicit !!map).

Block Mapping is used as the collection style. See 10.2.2. Block Mappings (http://yaml.org/spec/1.1/#id934537)
[中]将Java对象序列化为YAML字符串。用[$0$]覆盖默认的根标记。
此方法与Yaml.dump(data)类似,只是整个文档的根标记替换为Tag.MAP标记(隐式!!映射)。
块映射用作集合样式。见10.2.2。块映射(http://yaml.org/spec/1.1/#id934537)

代码示例

代码示例来源:origin: apache/incubator-shardingsphere

@Override
  public String dump(final Properties props) {
    return new Yaml(new DefaultYamlRepresenter()).dumpAsMap(props);
  }
}

代码示例来源:origin: apache/incubator-shardingsphere

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

代码示例来源:origin: apache/incubator-shardingsphere

@Override
  public String dump(final Map<String, Object> configMap) {
    return new Yaml(new DefaultYamlRepresenter()).dumpAsMap(configMap);
  }
}

代码示例来源:origin: apache/incubator-shardingsphere

@Override
  public String dump(final MasterSlaveRuleConfiguration masterSlaveRuleConfiguration) {
    return new Yaml(new DefaultYamlRepresenter()).dumpAsMap(new YamlMasterSlaveRuleConfiguration(masterSlaveRuleConfiguration));
  }
}

代码示例来源:origin: apache/incubator-shardingsphere

@Override
public String dump(final ShardingRuleConfiguration shardingRuleConfiguration) {
  return new Yaml(new DefaultYamlRepresenter()).dumpAsMap(createYamlShardingRuleConfiguration(shardingRuleConfiguration));
}

代码示例来源:origin: spring-cloud/spring-cloud-config

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

代码示例来源:origin: apache/incubator-shardingsphere

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

代码示例来源:origin: stackoverflow.com

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", "~"));

代码示例来源:origin: fhoeben/hsac-fitnesse-fixtures

@Override
protected String createContaining(String filename, Map<String, Object> map) {
  String yamlStr = yaml.dumpAsMap(map);
  return createContaining(filename, yamlStr);
}

代码示例来源:origin: io.smartcat/cassandra-diagnostics-core

/**
 * 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;
}

代码示例来源:origin: io.helixservice/helix-config

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

代码示例来源:origin: io.smartcat/cassandra-diagnostics-core

/**
 * 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;
}

代码示例来源:origin: io.smartcat/cassandra-diagnostics-core

/**
 * 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;
}

代码示例来源:origin: io.shardingsphere/sharding-orchestration-core

/**
 * 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);
}

代码示例来源:origin: io.shardingsphere/sharding-orchestration-core

/**
 * Dump authentication.
 *
 * @param authentication authentication
 * @return YAML string
 */
public static String dumpAuthentication(final Authentication authentication) {
  return new Yaml(new DefaultYamlRepresenter()).dumpAsMap(authentication);
}

代码示例来源:origin: io.shardingsphere/sharding-orchestration-core

/**
   * Dump properties configuration.
   *
   * @param props props
   * @return YAML string
   */
  public static String dumpProperties(final Properties props) {
    return new Yaml(new DefaultYamlRepresenter()).dumpAsMap(props);
  }
}

代码示例来源:origin: io.shardingsphere/sharding-orchestration-core

/**
 * 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));
}

代码示例来源:origin: io.shardingsphere/sharding-orchestration-core

/**
 * 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));
}

代码示例来源:origin: com.sap.cloud.lm.sl/com.sap.cloud.lm.sl.mta

public static String convertToYaml(Object object) {
  Yaml yaml = new Yaml(new SafeConstructor(), new YamlRepresenter());
  return yaml.dumpAsMap(object);
}

代码示例来源:origin: sonatype-nexus-community/nexus-repository-helm

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

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com