Java Code Examples for org.yaml.snakeyaml.error.YAMLException#getMessage()

The following examples show how to use org.yaml.snakeyaml.error.YAMLException#getMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: YmlParser.java    From flow-platform-x with Apache License 2.0 6 votes vote down vote up
/**
 * Create Node instance from yml
 */
public static synchronized FlowNode load(String defaultName, String yml) {
    Yaml yaml = YamlHelper.create(FlowYml.class);

    try {
        FlowYml root = yaml.load(yml);

        // set default flow name if not defined in yml
        if (Strings.isNullOrEmpty(root.getName())) {
            root.setName(defaultName);
        }

        return root.toNode();
    } catch (YAMLException e) {
        throw new YmlException(e.getMessage());
    }
}
 
Example 2
Source File: ReadOnlyPropertiesTest.java    From snake-yaml with Apache License 2.0 6 votes vote down vote up
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"));
    }
}
 
Example 3
Source File: YmlParser.java    From flow-platform-x with Apache License 2.0 5 votes vote down vote up
/**
 * Create Node instance from yml
 */
public static synchronized Node load(String defaultName, String yml) {
    Yaml yaml = YamlHelper.create(FlowNode.class);

    try {
        FlowNode root = yaml.load(yml);
        // set default flow name if not defined in yml
        if (Strings.isNullOrEmpty(root.getName())) {
            root.setName(defaultName);
        }

        if (!NodePath.validate(root.getName())) {
            throw new YmlException("Invalid name {0}", root.getName());
        }

        // steps must be provided
        List<StepNode> steps = root.getSteps();
        if (Objects.isNull(steps) || steps.isEmpty()) {
            throw new YmlException("The 'steps' must be defined");
        }

        Set<String> stepNames = new HashSet<>(steps.size());

        for (StepNode node : steps) {
            if (StringHelper.hasValue(node.getName()) && !NodePath.validate(node.getName())) {
                throw new YmlException("Invalid name '{0}'", node.name);
            }

            if (!stepNames.add(node.name)) {
                throw new YmlException("Duplicate step name {0}", node.name);
            }
        }

        return root.toNode(0);
    } catch (YAMLException e) {
        throw new YmlException(e.getMessage());
    }
}
 
Example 4
Source File: KaramelFile.java    From karamel with Apache License 2.0 5 votes vote down vote up
public KaramelFile(String fileContent) throws MetadataParseException {
  Yaml yaml = new Yaml(new Constructor(KaramelFileYamlRep.class));
  KaramelFileYamlRep file = null;
  try {
    file = (KaramelFileYamlRep) yaml.load(fileContent);
  } catch (YAMLException ex) {
    throw new MetadataParseException(ex.getMessage());
  }
  dependencies = new ArrayList<>();
  dependencies.addAll(file.getDependencies());
}