本文整理汇总了Java中org.yaml.snakeyaml.Yaml.dumpAsMap方法的典型用法代码示例。如果您正苦于以下问题:Java Yaml.dumpAsMap方法的具体用法?Java Yaml.dumpAsMap怎么用?Java Yaml.dumpAsMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.yaml.snakeyaml.Yaml
的用法示例。
在下文中一共展示了Yaml.dumpAsMap方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toYAML
import org.yaml.snakeyaml.Yaml; //导入方法依赖的package包/类
/**
* Marshals the supplied {@link Object} to YAML in the context of
* the supplied {@link Context} and returns the result.
*
* <p>This method never returns {@code null}.</p>
*
* <p>This method may call the {@link #createYaml()} method.</p>
*
* @param context the {@link Context} representing the write
* operation; must not be {@code null}
*
* @param data the {@link Object} to convert to its YAML
* representation; may be {@code null}
*
* @return a non-{@code null} {@link String} consisting of the
* appropriate YAML represesentation of the supplied {@code data}
*
* @exception IOException if a YAML serialization error occurs
*
* @exception NullPointerException if {@code context} is {@code
* null}
*
* @see #createYaml()
*
* @see Yaml#dumpAsMap(Object)
*/
protected final String toYAML(final Context context, final Object data) throws IOException {
Objects.requireNonNull(context);
Yaml yaml = context.get(Yaml.class.getName(), Yaml.class);
if (yaml == null) {
yaml = this.createYaml();
if (yaml == null) {
throw new IllegalStateException("createYaml() == null");
}
context.put(Yaml.class.getName(), yaml);
}
return yaml.dumpAsMap(data);
}