Java Code Examples for org.yaml.snakeyaml.introspector.PropertyUtils#setSkipMissingProperties()

The following examples show how to use org.yaml.snakeyaml.introspector.PropertyUtils#setSkipMissingProperties() . 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: ObjectMapItem.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
private Object loadYaml(File omapfile) throws IOException {
    FileReader reader = new FileReader(omapfile);
    try {
        Constructor constructor = new Constructor();
        PropertyUtils putils = new PropertyUtils();
        putils.setSkipMissingProperties(true);
        constructor.setPropertyUtils(putils);
        Yaml yaml = new Yaml(constructor);
        return yaml.load(reader);
    } catch (Throwable t) {
        throw new RuntimeException("Error loading yaml from: " + omapfile.getAbsolutePath() + "\n" + t.getMessage(), t);
    } finally {
        try {
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
 
Example 2
Source File: OMapContainer.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
private Object loadYaml(File file) throws FileNotFoundException {
    FileReader reader = new FileReader(file);
    try {
        Constructor constructor = new Constructor();
        PropertyUtils putils = new PropertyUtils();
        putils.setSkipMissingProperties(true);
        constructor.setPropertyUtils(putils);
        Yaml yaml = new Yaml(constructor);
        return yaml.load(reader);
    } catch (Throwable t) {
        throw new RuntimeException("Error loading yaml from: " + file.getAbsolutePath() + "\n" + t.getMessage(), t);
    } finally {
        try {
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
 
Example 3
Source File: YamlFactory.java    From waggle-dance with Apache License 2.0 6 votes vote down vote up
public static Yaml newYaml() {
  PropertyUtils propertyUtils = new AdvancedPropertyUtils();
  propertyUtils.setSkipMissingProperties(true);

  Constructor constructor = new Constructor(Federations.class);
  TypeDescription federationDescription = new TypeDescription(Federations.class);
  federationDescription.putListPropertyType("federatedMetaStores", FederatedMetaStore.class);
  constructor.addTypeDescription(federationDescription);
  constructor.setPropertyUtils(propertyUtils);

  Representer representer = new AdvancedRepresenter();
  representer.setPropertyUtils(new FieldOrderPropertyUtils());
  representer.addClassTag(Federations.class, Tag.MAP);
  representer.addClassTag(AbstractMetaStore.class, Tag.MAP);
  representer.addClassTag(WaggleDanceConfiguration.class, Tag.MAP);
  representer.addClassTag(YamlStorageConfiguration.class, Tag.MAP);
  representer.addClassTag(GraphiteConfiguration.class, Tag.MAP);

  DumperOptions dumperOptions = new DumperOptions();
  dumperOptions.setIndent(2);
  dumperOptions.setDefaultFlowStyle(FlowStyle.BLOCK);

  return new Yaml(constructor, representer, dumperOptions);
}
 
Example 4
Source File: YAMLConfigManager.java    From siddhi with Apache License 2.0 6 votes vote down vote up
/**
 * Initialises YAML Config Manager by parsing the YAML file
 *
 * @throws YAMLConfigManagerException Exception is thrown if there are issues in processing thr yaml file
 */
private void init(String yamlContent) throws YAMLConfigManagerException {
    try {
        CustomClassLoaderConstructor constructor = new CustomClassLoaderConstructor(
                RootConfiguration.class, RootConfiguration.class.getClassLoader());
        PropertyUtils propertyUtils = new PropertyUtils();
        propertyUtils.setSkipMissingProperties(true);
        constructor.setPropertyUtils(propertyUtils);

        Yaml yaml = new Yaml(constructor);
        yaml.setBeanAccess(BeanAccess.FIELD);
        this.rootConfiguration = yaml.load(yamlContent);
    } catch (Exception e) {
        throw new YAMLConfigManagerException("Unable to parse YAML string, '" + yamlContent + "'.", e);
    }
}
 
Example 5
Source File: MetaInfo.java    From ratel with Apache License 2.0 5 votes vote down vote up
private static Yaml getYaml() {
    DumperOptions options = new DumperOptions();
    options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);

    StringExRepresent representer = new StringExRepresent();
    PropertyUtils propertyUtils = representer.getPropertyUtils();
    propertyUtils.setSkipMissingProperties(true);

    return new Yaml(new StringExConstructor(), representer, options);
}