本文整理匯總了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);
}