Package org.yaml.snakeyaml

Examples of org.yaml.snakeyaml.Yaml.loadAs()


        CollectionSet bean = new CollectionSet();
        Yaml yaml = new Yaml();
        String doc = yaml.dumpAsMap(bean);
        // System.out.println(doc);
        Yaml beanLoader = new Yaml();
        CollectionSet parsed = beanLoader.loadAs(doc, CollectionSet.class);
        assertTrue(parsed.getRoles().contains(11));
        assertTrue(parsed.getRoles().contains(13));
        assertEquals(2, parsed.getRoles().size());
    }
View Full Code Here


        String output = yaml2.dumpAsMap(result);
        assertFalse("No tags expected.", output.contains("Sub1"));
        // System.out.println(output);
        // parse back. Without tags it shall still work
        Yaml beanLoader = new Yaml();
        TestObject result2 = beanLoader.loadAs(output, TestObject.class);
        assertEquals(0, result2.getSub1().getAtt2());
        assertEquals("MyString", result2.getSub2().getAtt1());
        assertEquals(1, result2.getSub2().getAtt2().size());
        assertEquals(12345, result2.getSub2().getAtt3());
    }
View Full Code Here

            InputStream yamlStream = file.toURL().openStream();

            if (yamlStream.available() == 0)
                throw new IOException("Unable to load yaml file from: "+file);

            StressYaml profileYaml = yaml.loadAs(yamlStream, StressYaml.class);

            StressProfile profile = new StressProfile();
            profile.init(profileYaml);

            return profile;
View Full Code Here

            seedDesc.putMapPropertyType("parameters", String.class, String.class);
            constructor.addTypeDescription(seedDesc);
            MissingPropertiesChecker propertiesChecker = new MissingPropertiesChecker();
            constructor.setPropertyUtils(propertiesChecker);
            Yaml yaml = new Yaml(constructor);
            Config result = yaml.loadAs(new ByteArrayInputStream(configBytes), Config.class);
            result.configHintedHandoff();
            propertiesChecker.check();
            return result;
        }
        catch (YAMLException e)
View Full Code Here

            seedDesc.putMapPropertyType("parameters", String.class, String.class);
            constructor.addTypeDescription(seedDesc);
            MissingPropertiesChecker propertiesChecker = new MissingPropertiesChecker();
            constructor.setPropertyUtils(propertiesChecker);
            Yaml yaml = new Yaml(constructor);
            Config result = yaml.loadAs(input, Config.class);
            result.configHintedHandoff();
            propertiesChecker.check();
            return result;
        }
        catch (YAMLException e)
View Full Code Here

            seedDesc.putMapPropertyType("parameters", String.class, String.class);
            constructor.addTypeDescription(seedDesc);
            MissingPropertiesChecker propertiesChecker = new MissingPropertiesChecker();
            constructor.setPropertyUtils(propertiesChecker);
            Yaml yaml = new Yaml(constructor);
            Config result = yaml.loadAs(input, Config.class);
            propertiesChecker.check();
            return result;
        }
        catch (YAMLException e)
        {
View Full Code Here

            Constructor constructor = new Constructor(StressYaml.class);

            Yaml yaml = new Yaml(constructor);

            StressYaml profileYaml = yaml.loadAs(new ByteArrayInputStream(profileBytes), StressYaml.class);

            StressProfile profile = new StressProfile();
            profile.init(profileYaml);

            return profile;
View Full Code Here

            seedDesc.putMapPropertyType("parameters", String.class, String.class);
            constructor.addTypeDescription(seedDesc);
            MissingPropertiesChecker propertiesChecker = new MissingPropertiesChecker();
            constructor.setPropertyUtils(propertiesChecker);
            Yaml yaml = new Yaml(constructor);
            Config result = yaml.loadAs(new ByteArrayInputStream(configBytes), Config.class);
            result.configHintedHandoff();
            propertiesChecker.check();
            return result;
        }
        catch (YAMLException e)
View Full Code Here

  @SuppressWarnings("unchecked")
  @Test
  public void testYaml() {
    Yaml yaml = new Yaml();
    Map<String, ?> map = yaml.loadAs("foo: bar\nspam:\n  foo: baz", Map.class);
    assertThat(map.get("foo"), equalTo((Object) "bar"));
    assertThat(((Map<String, Object>) map.get("spam")).get("foo"),
        equalTo((Object) "baz"));
  }
View Full Code Here

   * @throws FileNotFoundException
   */
  @SuppressWarnings("unchecked")
  public void load(InputStream inputStream) {
    Yaml yaml = new Yaml();
    config = yaml.loadAs(inputStream, Map.class);
  }
 
  /**
   * Get the full configuration
   * returns null if no configuration file is loaded
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.