Java Code Examples for org.yaml.snakeyaml.Yaml#setBeanAccess()
The following examples show how to use
org.yaml.snakeyaml.Yaml#setBeanAccess() .
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: TestUtils.java From ballerina-message-broker with Apache License 2.0 | 6 votes |
/** * Create master key file. * * @param file file instance * @param masterKeyConfiguration master key configuration */ public static void createMasterKeyFile(File file, MasterKeyConfiguration masterKeyConfiguration) { try { file.createNewFile(); file.deleteOnExit(); FileWriter fileWriter = new FileWriter(file); DumperOptions options = new DumperOptions(); options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); Representer representer = new Representer(); representer.addClassTag(MasterKeyConfiguration.class, Tag.MAP); Yaml yaml = new Yaml(representer, options); yaml.setBeanAccess(BeanAccess.FIELD); yaml.dump(masterKeyConfiguration, fileWriter); } catch (IOException e) { Assert.fail("Failed to create temp password file"); } }
Example 2
Source File: YAMLConfigManager.java From siddhi with Apache License 2.0 | 6 votes |
/** * 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 3
Source File: Utils.java From msf4j with Apache License 2.0 | 6 votes |
public static TransportsConfiguration resolveTransportsNSConfiguration(Object transportsConfig) throws ConfigurationException { TransportsConfiguration transportsConfiguration; if (transportsConfig instanceof Map) { LinkedHashMap httpConfig = ((LinkedHashMap) ((Map) transportsConfig).get("http")); if (httpConfig != null) { String configYaml = new Yaml().dump(httpConfig); Yaml yaml = new Yaml(new CustomClassLoaderConstructor(TransportsConfiguration.class, TransportsConfiguration.class.getClassLoader())); yaml.setBeanAccess(BeanAccess.FIELD); transportsConfiguration = yaml.loadAs(configYaml, TransportsConfiguration.class); } else { transportsConfiguration = new TransportsConfiguration(); } } else { throw new ConfigurationException("The first level config under 'transports' namespace should be " + "a map."); } return transportsConfiguration; }
Example 4
Source File: ArrayInGenericCollectionTest.java From snake-yaml with Apache License 2.0 | 6 votes |
public void testArrayAsMapValue() { Yaml yaml2dump = new Yaml(); yaml2dump.setBeanAccess(BeanAccess.FIELD); A data = createA(); String dump = yaml2dump.dump(data); // System.out.println(dump); Yaml yaml2load = new Yaml(); yaml2load.setBeanAccess(BeanAccess.FIELD); A loaded = (A) yaml2load.load(dump); assertEquals(data.meta.size(), loaded.meta.size()); Set<Entry<String, String[]>> loadedMeta = loaded.meta.entrySet(); for (Entry<String, String[]> entry : loadedMeta) { assertTrue(data.meta.containsKey(entry.getKey())); Assert.assertArrayEquals(data.meta.get(entry.getKey()), entry.getValue()); } }
Example 5
Source File: ContainerDataYaml.java From hadoop-ozone with Apache License 2.0 | 6 votes |
/** * Read the yaml content, and return containerData. * * @throws IOException */ public static ContainerData readContainer(InputStream input) throws IOException { ContainerData containerData; PropertyUtils propertyUtils = new PropertyUtils(); propertyUtils.setBeanAccess(BeanAccess.FIELD); propertyUtils.setAllowReadOnlyProperties(true); Representer representer = new ContainerDataRepresenter(); representer.setPropertyUtils(propertyUtils); Constructor containerDataConstructor = new ContainerDataConstructor(); Yaml yaml = new Yaml(containerDataConstructor, representer); yaml.setBeanAccess(BeanAccess.FIELD); containerData = (ContainerData) yaml.load(input); return containerData; }
Example 6
Source File: YamlFieldAccessCollectionTest.java From snake-yaml with Apache License 2.0 | 5 votes |
public void testYamlDefaultWithFeildAccess() { Yaml yaml = new Yaml(); yaml.setBeanAccess(BeanAccess.FIELD); Blog original = createTestBlog(); String serialized = yaml.dump(original); assertEquals(Util.getLocalResource("issues/issue55_1_rootTag.txt"), serialized); Blog rehydrated = (Blog) yaml.load(serialized); checkTestBlog(rehydrated); }
Example 7
Source File: FieldListTest.java From snake-yaml with Apache License 2.0 | 5 votes |
public void testYaml() { Yaml beanLoader = new Yaml(); beanLoader.setBeanAccess(BeanAccess.FIELD); BlogField rehydrated = beanLoader.loadAs(Util.getLocalResource("issues/issue55_2.txt"), BlogField.class); assertEquals(4, rehydrated.getPosts().size()); }
Example 8
Source File: SetAsSequenceTest.java From snake-yaml with Apache License 2.0 | 5 votes |
public void testLoad() { Yaml yaml = new Yaml(); yaml.setBeanAccess(BeanAccess.FIELD); String doc = Util.getLocalResource("issues/issue73-1.txt"); Blog blog = (Blog) yaml.load(doc); // System.out.println(blog); assertEquals("Test Me!", blog.getName()); assertEquals(2, blog.numbers.size()); assertEquals(2, blog.getPosts().size()); for (Post post : blog.getPosts()) { assertEquals(Post.class, post.getClass()); } }
Example 9
Source File: SetAsSequenceTest.java From snake-yaml with Apache License 2.0 | 5 votes |
public void testYaml() { String serialized = Util.getLocalResource("issues/issue73-2.txt"); // System.out.println(serialized); Yaml beanLoader = new Yaml(); beanLoader.setBeanAccess(BeanAccess.FIELD); Blog rehydrated = beanLoader.loadAs(serialized, Blog.class); checkTestBlog(rehydrated); }
Example 10
Source File: DumpSetAsSequenceExampleTest.java From snake-yaml with Apache License 2.0 | 5 votes |
private void check(String doc) { Yaml yamlLoader = new Yaml(); yamlLoader.setBeanAccess(BeanAccess.FIELD); Blog blog = (Blog) yamlLoader.load(doc); assertEquals("Test Me!", blog.getName()); assertEquals(2, blog.numbers.size()); assertEquals(2, blog.getPosts().size()); for (Post post : blog.getPosts()) { assertEquals(Post.class, post.getClass()); } }
Example 11
Source File: YamlFieldAccessCollectionTest.java From snake-yaml with Apache License 2.0 | 5 votes |
public void testYaml() { Blog original = createTestBlog(); Yaml yamlDumper = constructYamlDumper(); String serialized = yamlDumper.dumpAsMap(original); // System.out.println(serialized); assertEquals(Util.getLocalResource("issues/issue55_1.txt"), serialized); Yaml blogLoader = new Yaml(); blogLoader.setBeanAccess(BeanAccess.FIELD); Blog rehydrated = blogLoader.loadAs(serialized, Blog.class); checkTestBlog(rehydrated); }
Example 12
Source File: ArrayInGenericCollectionTest.java From snake-yaml with Apache License 2.0 | 5 votes |
public void testArrayAsListValue() { Yaml yaml2dump = new Yaml(); yaml2dump.setBeanAccess(BeanAccess.FIELD); B data = createB(); String dump = yaml2dump.dump(data); // System.out.println(dump); Yaml yaml2load = new Yaml(); yaml2load.setBeanAccess(BeanAccess.FIELD); B loaded = (B) yaml2load.load(dump); Assert.assertArrayEquals(data.meta.toArray(), loaded.meta.toArray()); }
Example 13
Source File: YamlSerializer.java From copper-engine with Apache License 2.0 | 5 votes |
protected Yaml initialYaml() { DumperOptions dO = new DumperOptions(); dO.setAllowReadOnlyProperties(true); Yaml yaml = new Yaml(dO); yaml.setBeanAccess(BeanAccess.FIELD); return yaml; }
Example 14
Source File: ArrayInGenericCollectionTest.java From snake-yaml with Apache License 2.0 | 5 votes |
public void testNoTags() { Yaml yaml2dump = new Yaml(); yaml2dump.setBeanAccess(BeanAccess.FIELD); B data = createB(); String dump = yaml2dump.dumpAs(data, Tag.MAP, FlowStyle.AUTO); // System.out.println(dump); assertEquals("meta:\n- [whatever]\n- [something, something else]\n", dump); // Constructor constr = new Constructor(B.class); Yaml yaml2load = new Yaml(constr); yaml2load.setBeanAccess(BeanAccess.FIELD); B loaded = (B) yaml2load.load(dump); Assert.assertArrayEquals(data.meta.toArray(), loaded.meta.toArray()); }
Example 15
Source File: ConfigSerializer.java From git-as-svn with GNU General Public License v2.0 | 5 votes |
public ConfigSerializer() { final DumperOptions options = new DumperOptions(); options.setPrettyFlow(true); options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); yaml = new Yaml(new ConfigConstructor(), new ConfigRepresenter(), options); yaml.setBeanAccess(BeanAccess.FIELD); }
Example 16
Source File: JavaBeanListTest.java From snake-yaml with Apache License 2.0 | 5 votes |
public void testYaml() { Yaml beanLoader = new Yaml(); beanLoader.setBeanAccess(BeanAccess.FIELD); BlogBean rehydrated = (BlogBean) beanLoader.loadAs( Util.getLocalResource("issues/issue55_2.txt"), BlogBean.class); assertEquals(4, rehydrated.getPosts().size()); }
Example 17
Source File: YamlFieldAccessCollectionTest.java From snake-yaml with Apache License 2.0 | 4 votes |
protected Yaml constructYamlParser() { Yaml yaml = new Yaml(); yaml.setBeanAccess(BeanAccess.FIELD); return yaml; }
Example 18
Source File: YamlSortedSetTest.java From snake-yaml with Apache License 2.0 | 4 votes |
protected Yaml constructYamlParser() { Yaml yaml = new Yaml(new SetContructor()); yaml.setBeanAccess(BeanAccess.FIELD); return yaml; }
Example 19
Source File: PropertyWithPrivateCostructorTest.java From snake-yaml with Apache License 2.0 | 4 votes |
private Yaml yaml() { Yaml _yaml = new Yaml(new OptionRepresenter()); _yaml.setBeanAccess(BeanAccess.FIELD); return _yaml; }
Example 20
Source File: Fixtures.java From restcommander with Apache License 2.0 | 3 votes |
/** * Load and parse a plain YAML file and returns the corresponding Java Map. * The YAML parser used is SnakeYAML (http://code.google.com/p/snakeyaml/) * @param name Name of a YAML file somewhere in the classpath (or conf/)me * @param clazz the expected class * @return Object representing the YAML data */ @SuppressWarnings("unchecked") public static <T> T loadYaml(String name, Class<T> clazz) { Yaml yaml = new Yaml(new CustomClassLoaderConstructor(clazz, Play.classloader)); yaml.setBeanAccess(BeanAccess.FIELD); return (T)loadYaml(name, yaml); }