Search in sources :

Example 1 with Representer

use of org.yaml.snakeyaml.representer.Representer in project mxgwd by kamax-io.

the class YamlConfigLoader method loadFromFile.

public static Config loadFromFile(String path) throws IOException {
    Representer rep = new Representer();
    rep.getPropertyUtils().setAllowReadOnlyProperties(true);
    rep.getPropertyUtils().setSkipMissingProperties(true);
    Yaml yaml = new Yaml(new Constructor(Config.class), rep);
    Object o = yaml.load(new FileInputStream(path));
    return GsonUtil.get().fromJson(GsonUtil.get().toJson(o), Config.class);
}
Also used : Representer(org.yaml.snakeyaml.representer.Representer) Constructor(org.yaml.snakeyaml.constructor.Constructor) Config(io.kamax.mxgwd.config.Config) Yaml(org.yaml.snakeyaml.Yaml) FileInputStream(java.io.FileInputStream)

Example 2 with Representer

use of org.yaml.snakeyaml.representer.Representer in project pai by Microsoft.

the class YamlUtils method toObject.

// Bytes <-> Yaml
public static <T> T toObject(byte[] bytes, Class<T> classRef) {
    Representer representer = new Representer();
    representer.getPropertyUtils().setSkipMissingProperties(true);
    Yaml yaml = new Yaml(new Constructor(classRef), representer);
    return yaml.loadAs(new String(bytes), classRef);
}
Also used : Representer(org.yaml.snakeyaml.representer.Representer) Constructor(org.yaml.snakeyaml.constructor.Constructor) Yaml(org.yaml.snakeyaml.Yaml)

Example 3 with Representer

use of org.yaml.snakeyaml.representer.Representer in project pai by Microsoft.

the class YamlUtils method toObject.

public static <T> T toObject(String fileName, Class<T> classRef) throws FileNotFoundException {
    Representer representer = new Representer();
    representer.getPropertyUtils().setSkipMissingProperties(true);
    Yaml yaml = new Yaml(new Constructor(classRef), representer);
    return yaml.loadAs(new FileReader(fileName), classRef);
}
Also used : Representer(org.yaml.snakeyaml.representer.Representer) Constructor(org.yaml.snakeyaml.constructor.Constructor) FileReader(java.io.FileReader) Yaml(org.yaml.snakeyaml.Yaml)

Example 4 with Representer

use of org.yaml.snakeyaml.representer.Representer in project pom-manipulation-ext by release-engineering.

the class YamlTest method readYamlViaMap.

@Test
public void readYamlViaMap() throws ManipulationException, IOException {
    Representer representer = new Representer();
    representer.getPropertyUtils().setSkipMissingProperties(true);
    Yaml y = new Yaml(representer);
    Map config = (Map) y.load(new FileInputStream(yamlFile));
    Map usersConfig = (Map) config.get("pme");
    assertTrue(usersConfig.size() > 0);
}
Also used : Representer(org.yaml.snakeyaml.representer.Representer) Map(java.util.Map) Yaml(org.yaml.snakeyaml.Yaml) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 5 with Representer

use of org.yaml.snakeyaml.representer.Representer in project winery by eclipse.

the class ChefKitchenYmlParser method parseKitchen.

private Map<String, Object> parseKitchen() {
    Representer representer = new Representer();
    representer.getPropertyUtils().setSkipMissingProperties(true);
    Yaml yaml = new Yaml();
    InputStream inputStream = null;
    try {
        inputStream = new FileInputStream(this.cookbookPath + "/kitchen.yml");
    } catch (FileNotFoundException e1) {
        try {
            inputStream = new FileInputStream(this.cookbookPath + "/.kitchen.yml");
        } catch (FileNotFoundException e2) {
            System.err.printf("Cookbook \" " + cookbookName + "\"" + " has no kitchen.yml file");
            return null;
        }
    }
    Map<String, Object> kitchenYml = yaml.load(inputStream);
    try {
        inputStream.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return kitchenYml;
}
Also used : Representer(org.yaml.snakeyaml.representer.Representer) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Yaml(org.yaml.snakeyaml.Yaml) FileInputStream(java.io.FileInputStream)

Aggregations

Representer (org.yaml.snakeyaml.representer.Representer)11 Yaml (org.yaml.snakeyaml.Yaml)10 FileInputStream (java.io.FileInputStream)5 Constructor (org.yaml.snakeyaml.constructor.Constructor)4 DumperOptions (org.yaml.snakeyaml.DumperOptions)3 FileNotFoundException (java.io.FileNotFoundException)2 Config (io.kamax.mxgwd.config.Config)1 File (java.io.File)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Map (java.util.Map)1 Properties (java.util.Properties)1 ManipulationException (org.commonjava.maven.ext.common.ManipulationException)1 YamlFile (org.commonjava.maven.ext.common.model.YamlFile)1 GradleException (org.gradle.api.GradleException)1 InputFile (org.gradle.api.tasks.InputFile)1 TaskAction (org.gradle.api.tasks.TaskAction)1 Test (org.junit.Test)1 LoaderOptions (org.yaml.snakeyaml.LoaderOptions)1