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

x33g5p2x  于2022-02-05 转载在 其他  
字(5.2k)|赞(0)|评价(0)|浏览(501)

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

Yaml.dumpAs介绍

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

This method is similar to Yaml.dump(data) except that the root tag for the whole document is replaced with the given tag. This has two main uses.

First, if the root tag is replaced with a standard YAML tag, such as Tag.MAP, then the object will be dumped as a map. The root tag will appear as !!map, or blank (implicit !!map).

Second, if the root tag is replaced by a different custom tag, then the document appears to be a different type when loaded. For example, if an instance of MyClass is dumped with the tag !!YourClass, then it will be handled as an instance of YourClass when loaded.
[中]将Java对象序列化为YAML字符串。用[$0$]覆盖默认的根标记。
此方法与Yaml.dump(data)类似,只是整个文档的根标记被给定的标记替换。这有两个主要用途。
首先,如果根标记替换为标准YAML标记,例如Tag.MAP,那么对象将作为映射转储。根标记将显示为[$3$],或空白(隐式!!映射)。
其次,如果根标记被另一个自定义标记替换,则文档在加载时似乎是另一种类型。例如,如果MyClass的一个实例与标记一起转储!!YourClass,则在加载时它将作为YourClass的实例进行处理。

代码示例

代码示例来源:origin: redisson/redisson

/**
 * <p>
 * Serialize a Java object into a YAML string. Override the default root tag
 * with <code>Tag.MAP</code>.
 * </p>
 * <p>
 * This method is similar to <code>Yaml.dump(data)</code> except that the
 * root tag for the whole document is replaced with <code>Tag.MAP</code> tag
 * (implicit !!map).
 * </p>
 * <p>
 * Block Mapping is used as the collection style. See 10.2.2. Block Mappings
 * (http://yaml.org/spec/1.1/#id934537)
 * </p>
 *
 * @param data
 *            Java object to be serialized to YAML
 * @return YAML String
 */
public String dumpAsMap(Object data) {
  return dumpAs(data, Tag.MAP, FlowStyle.BLOCK);
}

代码示例来源: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: harbby/presto-connectors

/**
 * <p>
 * Serialize a Java object into a YAML string. Override the default root tag
 * with <code>Tag.MAP</code>.
 * </p>
 * <p>
 * This method is similar to <code>Yaml.dump(data)</code> except that the
 * root tag for the whole document is replaced with <code>Tag.MAP</code> tag
 * (implicit !!map).
 * </p>
 * <p>
 * Block Mapping is used as the collection style. See 10.2.2. Block Mappings
 * (http://yaml.org/spec/1.1/#id934537)
 * </p>
 * 
 * @param data
 *            Java object to be serialized to YAML
 * @return YAML String
 */
public String dumpAsMap(Object data) {
  return dumpAs(data, Tag.MAP, FlowStyle.BLOCK);
}

代码示例来源:origin: pl.droidsonroids.yaml/snakeyaml

/**
 * <p>
 * Serialize a Java object into a YAML string. Override the default root tag
 * with <code>Tag.MAP</code>.
 * </p>
 * <p>
 * This method is similar to <code>Yaml.dump(data)</code> except that the
 * root tag for the whole document is replaced with <code>Tag.MAP</code> tag
 * (implicit !!map).
 * </p>
 * <p>
 * Block Mapping is used as the collection style. See 10.2.2. Block Mappings
 * (http://yaml.org/spec/1.1/#id934537)
 * </p>
 * 
 * @param data
 *            Java object to be serialized to YAML
 * @return YAML String
 */
public String dumpAsMap(Object data) {
  return dumpAs(data, Tag.MAP, FlowStyle.BLOCK);
}

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

/**
 * <p>
 * Serialize a Java object into a YAML string. Override the default root tag
 * with <code>Tag.MAP</code>.
 * </p>
 * <p>
 * This method is similar to <code>Yaml.dump(data)</code> except that the
 * root tag for the whole document is replaced with <code>Tag.MAP</code> tag
 * (implicit !!map).
 * </p>
 * <p>
 * Block Mapping is used as the collection style. See 10.2.2. Block Mappings
 * (http://yaml.org/spec/1.1/#id934537)
 * </p>
 *
 * @param data
 *            Java object to be serialized to YAML
 * @return YAML String
 */
public String dumpAsMap(Object data) {
  return dumpAs(data, Tag.MAP, FlowStyle.BLOCK);
}

代码示例来源:origin: com.gitblit.iciql/iciql

@Override
public Object serialize(Object value) {
  return yaml().dumpAs(value, Tag.MAP, FlowStyle.BLOCK);
}

代码示例来源:origin: gitblit/iciql

@Override
public Object serialize(Object value) {
  return yaml().dumpAs(value, Tag.MAP, FlowStyle.BLOCK);
}

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

@Override
public String createContaining(String filename, Object data) {
  String file;
  if (data instanceof Map
      || data instanceof byte[]
      || data instanceof String) {
    file = valuesFileCreateContaining(filename, data);
  } else {
    String yamlStr = yaml.dumpAs(data, null, DumperOptions.FlowStyle.BLOCK);
    file = createContaining(filename, yamlStr);
  }
  return file;
}

代码示例来源:origin: CodeCrafter47/BungeeTabListPlus

String ser = yaml.dumpAs(object, Tag.MAP, null);

相关文章