本文整理汇总了Java中org.yaml.snakeyaml.error.YAMLException.getMessage方法的典型用法代码示例。如果您正苦于以下问题:Java YAMLException.getMessage方法的具体用法?Java YAMLException.getMessage怎么用?Java YAMLException.getMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.yaml.snakeyaml.error.YAMLException
的用法示例。
在下文中一共展示了YAMLException.getMessage方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBean2
import org.yaml.snakeyaml.error.YAMLException; //导入方法依赖的package包/类
public void testBean2() {
IncompleteBean bean = new IncompleteBean();
bean.setName("lunch");
DumperOptions options = new DumperOptions();
options.setAllowReadOnlyProperties(true);
Yaml yaml = new Yaml(options);
String output = yaml.dumpAsMap(bean);
// System.out.println(output);
assertEquals("id: 10\nname: lunch\n", output);
//
Yaml loader = new Yaml();
try {
loader.loadAs(output, IncompleteBean.class);
fail("Setter is missing.");
} catch (YAMLException e) {
String message = e.getMessage();
assertTrue(
message,
message.contains("Unable to find property 'id' on class: org.yaml.snakeyaml.issues.issue47.IncompleteBean"));
}
}
示例2: readYamlFile
import org.yaml.snakeyaml.error.YAMLException; //导入方法依赖的package包/类
Map<String, Object> readYamlFile(String yamlfile) throws FileNotFoundException {
File file = new File(yamlfile);
if (file.exists()) {
InputStream input = new FileInputStream(file);
Yaml yaml = new Yaml();
Object data;
try {
data = yaml.load(input);
} catch (YAMLException ye) {
throw new PivioYamlParserException("Data in " + yamlfile + " is not valid: "+ye.getMessage());
}
if (data instanceof Map) {
return makeLowerCaseKeys((Map<String, Object>) data);
} else {
throw new PivioYamlParserException("Data in " + yamlfile + " is not valid.");
}
} else {
throw new FileNotFoundException("Could not find " + yamlfile + ".");
}
}
示例3: buildFromYml
import org.yaml.snakeyaml.error.YAMLException; //导入方法依赖的package包/类
/**
* Verify and create node tree by yml
*
* @param yml raw yml string
* @return root node of yml
* @throws YmlException if yml format is illegal
*/
public static Node buildFromYml(String yml, String rootName) {
try {
Yaml yaml = new Yaml(ROOT_YML_CONSTRUCTOR);
RootYmlWrapper node = yaml.load(yml);
// verify flow node
if (Objects.isNull(node.flow)) {
throw new YmlException("The 'flow' content must be defined");
}
// current version only support single flow
if (node.flow.size() > 1) {
throw new YmlException("Unsupported multiple flows definition");
}
// steps must be provided
List<NodeWrapper> steps = node.flow.get(0).steps;
if (Objects.isNull(steps) || steps.isEmpty()) {
throw new YmlException("The 'step' must be defined");
}
node.flow.get(0).name = rootName;
Node root = node.flow.get(0).toNode();
buildNodeRelation(root);
VALIDATOR.validate(root);
return root;
} catch (YAMLException e) {
throw new YmlException(e.getMessage());
}
}