Giter VIP home page Giter VIP logo

snakeyaml's People

Contributors

asomov avatar jordanangold avatar maslovalex avatar splatch avatar

Watchers

 avatar

snakeyaml's Issues

List or Map of Maps doesn't work in 1.5

What steps will reproduce the problem?

Create a yaml file (4 lines):

- a:
    b: c
- d:
    e: f

Try to load it with snakeyaml

What is the expected output? What do you see instead?

I expected a List<Map<String, Map<String, String>>> to pop out.

What version of the product are you using? On what operating system?

snakeyaml 1.5
java 1.6

Please provide any additional information below.

It works perfectly fine in http://instantyaml.appspot.com/ and
http://yaml-online-parser.appspot.com/

Original issue reported on code.google.com by [email protected] on 7 Jan 2010 at 2:16

Simplify dumping (serializing) of immutable objects

Immutable objects are serialized by default as JavaBeans (as mappings).
This is inconvenient since they cannot be de-serialized (parsed) afterwards.
Currently it is necessary to write a custom Representer to dump immutable 
objects as sequences. It should be somehow simplified.



Original issue reported on code.google.com by [email protected] on 17 Sep 2009 at 12:29

does not dump maps of beans correctly

What steps will reproduce the problem?

import java.io.*;
import java.util.*;
import junit.framework.TestCase;
import org.yaml.snakeyaml.Yaml;

public class MapYamlTest extends TestCase {

    public void testYamlMap() throws IOException {
        Map<String, Bean> data = new TreeMap<String, Bean>();
        data.put("gold1", new Bean());
        data.put("gold2", new Bean());

        Yaml yaml = new Yaml();
        File file = new File("beantest.yml");

        FileOutputStream os = new FileOutputStream(file);
        yaml.dump(data, new OutputStreamWriter(os));
        os.close();

        FileInputStream is = new FileInputStream(file);
        Object o = yaml.load(new InputStreamReader(is));
        is.close();

        assertTrue(o instanceof Map);
        Map m = (Map)o;
        assertTrue(m.get("gold1") instanceof Bean);
        assertTrue(m.get("gold2") instanceof Bean);
    }

    public static class Bean {
        private String a;
        public Bean() { a = ""; }
        public String getA() { return a; }
        public void setA(String s) { a = s; }

    }

}


What is the expected output? What do you see instead?

Test should pass. However, it fails on the last assert. If you look at
beantest.yml it has this:

gold1: !![package omitted]MapYamlTest$Bean {a: ''}
gold2: {a: ''}

In other words, it's only writing the tag for the first entry in the map.


What version of the product are you using? On what operating system?

Latest SnakeYAML from the hg repo, on Debian


Please provide any additional information below.

N/A

Original issue reported on code.google.com by [email protected] on 2 Jul 2009 at 4:54

Enchancement Request: break value representation into separate method

Starting at line 103 of Representer.java, it would be nice if a sub class could 
decide how to 
represent that specific value. getProperties allows a subclass to determine 
which properties get 
written as a whole, but it would be nice to not write out nulls or default 
values in certain situations. 

Replacing all of representJavaBean, the other option, makes the subclass more 
fragile. 

Original issue reported on code.google.com by [email protected] on 11 Feb 2010 at 9:53

Bean with no property cannot be instantiated

The following yaml documents cannot be read, but should.

--- !!org.yaml.snakeyaml.noprop.BeanHolder
bean : !!org.yaml.snakeyaml.noprop.Bean1

--- !!org.yaml.snakeyaml.noprop.BeanHolder

The attached patch contains testcases that reproduce the problem.

Original issue reported on code.google.com by [email protected] on 22 Jul 2009 at 7:53

Attachments:

Spurious object recursion perhaps due to misuse of System.identityHashCode()

If you run YAML long enough, it will create random recursive links where
ones shouldn't exist. I guess this is because it assumes
System.identityHashCode() will always return different values for the same
object; this is NOT the case:

$ grep -R "identityHashCode" .
./Yaml.java:        this.name = "Yaml:" + System.identityHashCode(this);
./nodes/MappingNode.java:           
buf.append(System.identityHashCode(node[1]));
./representer/BaseRepresenter.java:        aliasKey =
System.identityHashCode(data);// take memory address

(the comment is wrong, the hashcode *some function* of the memory address
used when the object is *first allocated*)

If it all that's needed is an identity map, you can use IdentityHashMap; it
will keep track of objects correctly even if they have the same
identityHashCode, it will just put them into the same bucket. ie:

representer/BaseRepresenter.java:

    protected final Map<Integer, Node> representedObjects = new
HashMap<Integer, Node>();

change this to

    protected final Map<Object, Node> representedObjects = new
IdentityHashMap<Object, Node>();

To test this, generate around 2^16 random objects and save them in the same
file. (This is approximately the expected number of hashes needed to see a
collision between any two of them, for a 32-bit sized hash code.)

Original issue reported on code.google.com by [email protected] on 13 Jul 2009 at 9:55

Potential Patch submission

While waiting for my employers blessing,

How would you like a patch submission/discussion to happen?

It is about some flexibility with the API not about the Yaml parsing. 
Namely taking a valid yaml file translated to nodes, and then grabbing the
anchors before construction time and tweaking them as I please before
continuing with the regular construction process.

This provides runtime argument-like passing behaviour to happen in a valid
Yaml way.  One makes a yaml tree from a template.  And so on.

Original issue reported on code.google.com by [email protected] on 3 Nov 2009 at 12:18

Unable to build with Java5

Since revision 452424220c
http://java.sun.com/javase/6/docs/api/java/lang/String.html#isEmpty()
utilized in unit tests. But isEmpty() method in java.lang.String available
only in Java6+.

Original issue reported on code.google.com by mykola.nickishov on 29 Jun 2009 at 8:50

unable to serialize a bean more than once using the same Yaml instance

I'm unable to serialize a bean more than once using the same Yaml   
instance. After the first bean is serialized, subsequent beans are not   
serialized as beans, they are serialized as maps. It seems that some   
variables to determine if the object is the root object do not get   
reset after the first call. (isRoot in Representer). 
Here is a gist with my failed test case. You can probably work it into   
your existing tests easily. 
http://gist.github.com/151188 
Alan Gutierrez 


Original issue reported on code.google.com by [email protected] on 21 Jul 2009 at 9:31

Cannot create JavaBean containing custom object with no copy constructor

This fails on SnakeYAML-1.3. On 1.4-SNAPSHOT, the test fails as per
issue#11 before it can get to this stage.

The test succeeds if you remove the third (copy) constructor.


import junit.framework.TestCase;

import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.error.YAMLException;
import org.yaml.snakeyaml.Loader;
import org.yaml.snakeyaml.Dumper;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.representer.Representer;
import org.yaml.snakeyaml.representer.Represent;
import org.yaml.snakeyaml.nodes.Node;
import org.yaml.snakeyaml.nodes.ScalarNode;
import org.yaml.snakeyaml.nodes.MappingNode;
import org.yaml.snakeyaml.constructor.Constructor;
import org.yaml.snakeyaml.constructor.Construct;
import org.yaml.snakeyaml.constructor.ConstructorException;

import java.io.*;
import java.util.*;

/**
** @author infinity0
*/
public class YamlMapTest extends TestCase {

    public void testYamlMap() throws IOException {
        Map<String, Object> data = new TreeMap<String, Object>();
        //data.put("key1", new Bean());
        //data.put("key2", new Bean());
        data.put("key3", new Custom("test"));
        data.put("key4", new Wrapper("test", new Custom("test")));

        Yaml yaml = new Yaml(new Loader(new ExtendedConstructor()),
                            new Dumper(new ExtendedRepresenter(), new DumperOptions()));
        File file = new File("beantest.yml");

        FileOutputStream os = new FileOutputStream(file);
        yaml.dump(data, new OutputStreamWriter(os));
        os.close();

        FileInputStream is = new FileInputStream(file);
        Object o = yaml.load(new InputStreamReader(is));
        is.close();

        assertTrue(o instanceof Map);
        Map m = (Map)o;
        //assertTrue(m.get("key1") instanceof Bean);
        // NOTE these tests fail in snakeYAML 1.2 and below, fixed in 1.3
        //assertTrue(m.get("key2") instanceof Bean);
        assertTrue(m.get("key3") instanceof Custom);
        assertTrue(m.get("key4") instanceof Wrapper);
    }
/*
    public static class Bean {
        private String a;
        public Bean() { a = ""; }
        public String getA() { return a; }
        public void setA(String s) { a = s; }

    }
*/
    public static class Wrapper {
        private String a;
        private Custom b;
        public Wrapper(String s, Custom bb) { a = s; b = bb; }
        public Wrapper() { }
        public String getA() { return a; }
        public void setA(String s) { a = s; }
        public Custom getB() { return b; }
        public void setB(Custom bb) { b = bb; }
    }

    public static class Custom {
        final private String str;
        public Custom(String s) {
            str = s;
        }
        public Custom(Integer i) {
            str = "";
        }
        /*public Custom(Custom c) {
            str = c.str;
        }*/
        public String toString() { return str; }
    }


    public static class ExtendedRepresenter extends Representer {
        public ExtendedRepresenter() {
            this.representers.put(Custom.class, new RepresentCustom());
        }

        private class RepresentCustom implements Represent {
            @Override public Node representData(Object data) {
                return representScalar("!Custom", ((Custom) data).toString());
            }
        }
    }


    public static class ExtendedConstructor extends Constructor {
        public ExtendedConstructor() {
            this.yamlConstructors.put("!Custom", new ConstructCustom());
        }

        private class ConstructCustom implements Construct {
            @Override public Object construct(Node node) {
                String str = (String) constructScalar((ScalarNode)node);
                return new Custom(str);
            }
            @Override public void construct2ndStep(Node node, Object object) { }
        }
    }

}



    [junit] Testcase: testYamlMap took 0.087 sec
    [junit]     Caused an ERROR
    [junit] null; Can't construct a java object for
tag:yaml.org,2002:plugins.Library.serial.YamlMapTest$Wrapper;
exception=org.yaml.snakeyaml.error.YAMLException:
java.lang.NoSuchMethodException:
plugins.Library.serial.YamlMapTest$Custom.<init>(plugins.Library.serial.YamlMapT
est$Custom)
    [junit] Can't construct a java object for
tag:yaml.org,2002:plugins.Library.serial.YamlMapTest$Wrapper;
exception=org.yaml.snakeyaml.error.YAMLException:
java.lang.NoSuchMethodException:
plugins.Library.serial.YamlMapTest$Custom.<init>(plugins.Library.serial.YamlMapT
est$Custom)
    [junit]  in "<reader>", line 1, column 6
    [junit] 
    [junit]     at
org.yaml.snakeyaml.constructor.Constructor$ConstructYamlObject.construct(Constru
ctor.java:141)
    [junit]     at
org.yaml.snakeyaml.constructor.BaseConstructor.callConstructor(BaseConstructor.j
ava:117)
    [junit]     at
org.yaml.snakeyaml.constructor.Constructor.callConstructor(Constructor.java:151)
    [junit]     at
org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.j
ava:107)
    [junit]     at
org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping2ndStep(BaseConst
ructor.java:189)
    [junit]     at
org.yaml.snakeyaml.constructor.SafeConstructor.constructMapping2ndStep(SafeConst
ructor.java:104)
    [junit]     at
org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping(BaseConstructor.
java:170)
    [junit]     at
org.yaml.snakeyaml.constructor.SafeConstructor$ConstructYamlMap.construct(SafeCo
nstructor.java:423)
    [junit]     at
org.yaml.snakeyaml.constructor.BaseConstructor.callConstructor(BaseConstructor.j
ava:117)
    [junit]     at
org.yaml.snakeyaml.constructor.Constructor.callConstructor(Constructor.java:151)
    [junit]     at
org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.j
ava:107)
    [junit]     at
org.yaml.snakeyaml.constructor.BaseConstructor.constructDocument(BaseConstructor
.java:74)
    [junit]     at
org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.jav
a:68)
    [junit]     at org.yaml.snakeyaml.Loader.load(Loader.java:39)
    [junit]     at org.yaml.snakeyaml.Yaml.load(Yaml.java:164)
    [junit]     at
plugins.Library.serial.YamlMapTest.testYamlMap(YamlMapTest.java:47)
    [junit] Caused by: org.yaml.snakeyaml.error.YAMLException:
org.yaml.snakeyaml.error.YAMLException: java.lang.NoSuchMethodException:
plugins.Library.serial.YamlMapTest$Custom.<init>(plugins.Library.serial.YamlMapT
est$Custom)
    [junit]     at
org.yaml.snakeyaml.constructor.Constructor.constructJavaBeanNode2ndStep(Construc
tor.java:388)
    [junit]     at
org.yaml.snakeyaml.constructor.Constructor.constructJavaBeanNode(Constructor.jav
a:335)
    [junit]     at
org.yaml.snakeyaml.constructor.Constructor.access$200(Constructor.java:33)
    [junit]     at
org.yaml.snakeyaml.constructor.Constructor$ConstructYamlObject.construct(Constru
ctor.java:108)
    [junit] Caused by: org.yaml.snakeyaml.error.YAMLException:
java.lang.NoSuchMethodException:
plugins.Library.serial.YamlMapTest$Custom.<init>(plugins.Library.serial.YamlMapT
est$Custom)
    [junit]     at
org.yaml.snakeyaml.constructor.Constructor.constructJavaBeanScalarNode(Construct
or.java:296)
    [junit]     at
org.yaml.snakeyaml.constructor.Constructor.callConstructor(Constructor.java:156)
    [junit]     at
org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.j
ava:107)
    [junit]     at
org.yaml.snakeyaml.constructor.Constructor.constructJavaBeanNode2ndStep(Construc
tor.java:381)
    [junit] Caused by: java.lang.NoSuchMethodException:
plugins.Library.serial.YamlMapTest$Custom.<init>(plugins.Library.serial.YamlMapT
est$Custom)
    [junit]     at java.lang.Class.getConstructor0(Class.java:2723)
    [junit]     at java.lang.Class.getConstructor(Class.java:1674)
    [junit]     at
org.yaml.snakeyaml.constructor.Constructor.constructJavaBeanScalarNode(Construct
or.java:291)
    [junit] 

Original issue reported on code.google.com by [email protected] on 5 Aug 2009 at 9:14

dump wrongfully omits JavaBean class name

STEPS TO REPRODUCE:
Run BasicDumpTest.java, which generates an error.

OUTPUT OF DUMP:

!!DataSources
dataSources:
- &id001 {name: null}
- name: null
  parent: *id001
  password: null
  url: null
  username: null

EXPECTED OUTPUT:

!!DataSources
dataSources:
- &id001 !!DataSource {name: null}
- !!JDBCDataSource 
  name: null
  parent: *id001
  password: null
  url: null
  username: null


VERSION
snakeyaml 1.3

Original issue reported on code.google.com by [email protected] on 27 Jul 2009 at 9:03

Attachments:

Documentation for Custom document doesn't compile

In the manual:

            String val = (String) constructScalar(node);

doesn't compile, since the method doesn't work with a node.

Also, the test case for Dice doesn't seem to be working (since nodes does
not contain a Tag).

I can't get a Custom Document writer to work. Is there other working
examples other than the Dice?

Original issue reported on code.google.com by [email protected] on 15 Jan 2010 at 7:10

Option to ignore unknown tags

If the loader encounters a tag it cannot resolve to a java class an
exception is thrown. I need an option that causes the loader to ignore such
tags (and as a result use the default types for map, seq, str).

Example YAML input file:

center: !Point [1,1]
city: !Place 12345 Springfield

Now assume that we have a constructor defined for !Point but not !Place. If
I read this file, I get an exception. But I need the datastructure as
produced by:

Map<String, Object> map = ...
map.put("center", new Point(1,1));
map.put("city", "43925 Springfield");

It should simply ignore !Place and use String instead. If the unknown tag
is on a map/seq, it should use Map/List.


Original issue reported on code.google.com by [email protected] on 13 Nov 2009 at 4:10

Extend Resolver to support custom implicit types

Sometimes resolver may report an implicit type where a string is expected.
For instance:
version: 1.0

1.0 - is not a float but a string.

There shall be a possibility to ignore some implicit types.


Original issue reported on code.google.com by [email protected] on 27 Oct 2009 at 3:16

Dump a java.io.File object

Hi,

I would like to dump a simple java.io.File object.
But I get a StackOverflowError by the Representer.
Is this correct?

To load a simple java.io.File object like
file: !!java.io.File /path/name
works fine.

I'm using version 1.5 on SLES 10


Thanks in advance.

Andi

Original issue reported on code.google.com by [email protected] on 25 Jan 2010 at 10:57

Problems deserializing bean properties of type "Long" when scalars are in double quotes

Hi,

Snakeyaml doesn't seem to be able to properly deserialize Long values
in beans when the original was serialized with
DumperOptions.ScalarStyle.DOUBLE_QUOTED enabled.

The way I see it, at deserialization time the numeric value
is parsed as Integer or Long depending on its size, and then snakeyaml
attempts to feed the bean's setter with it as-is.

This works fine if the value is actually outside the range of an
integer (which seems to be the case covered by the tests), but once
the value would fit in an Integer this system breaks down (trying to
pass an Integer to a Long setter).

Example test:

-----------
package org.yaml.snakeyaml.javabeans;

import junit.framework.TestCase;

import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.DumperOptions;

public class LongTest extends TestCase {
    public void testLong() {
        DumperOptions options = new DumperOptions();
        options.setDefaultScalarStyle(DumperOptions.ScalarStyle.DOUBLE_QUOTED);

        Yaml yaml = new Yaml(options);

        Foo foo = new Foo();
        String output = yaml.dump(foo);
        System.out.println(output);
        Foo foo2 = (Foo) yaml.load(output);
        assertEquals(new Long(42L), foo2.getBar());
    }

    public static class Foo {
        private Long bar = Long.valueOf(42L);

        public Long getBar() {
            return bar;
        }

        public void setBar(Long bar) {
            this.bar = bar;
        }
    }
}
------------

I'm using snakeyaml-1.4 (release package).

Original issue reported on code.google.com by [email protected] on 3 Sep 2009 at 11:05

Preserve YAML comments when roundtripping...

We use YAML as a configuration language in our Okapi localization framework
(http://code.google.com/p/okapi/) - it would be great if SnakeYaml could
preserve our comments when we load then dump our yaml files. Otherwise
SnakeYaml dump is very clean! 

Original issue reported on code.google.com by [email protected] on 17 Sep 2009 at 8:54

I cannot deserialise into a Vector object.

What steps will reproduce the problem?
1. Create a Vector object, add several String entries, and serialise it.
2. Try to deserialise the obtained YAML string into another Vector object.


What is the expected output? What do you see instead?
- The expected output after the deserialisation is a new Vector object with
the same entries added into the source object. Instead of this a
ClassCastException is thrown since the YAML decoder output is a LinkedList
object.

What version of the product are you using? On what operating system?
- I am using the last development version.

Please provide any additional information below.
- I want to state that, just before the deserialisation, I have initialised
the Constructor class with name of the class I expected to obtain: 

new Yaml(new Loader(new Constructor("java.util.Vector")))

- I have included a code that demonstrates the issue.


Original issue reported on code.google.com by [email protected] on 3 Sep 2009 at 11:04

Attachments:

SnakeYAML installation/import errors

Hello,

The Docu just says for installation to put the source file into the
classpath !?

I repacked the snakeyaml folder  contents of SnakeYAML-all-1.5.zip into
Snakeyaml-1.5.zip and imported it in Eclipse with File>Import…>Existing
Projects into Workspace>Select archive file.
I get the fallowing errors:

The project cannot be built until build path errors are resolved SnakeYAML
Unknown Java Problem

Unbound classpath variable:
'M2_REPO/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar'
in project 'SnakeYAML' SnakeYAML Build path Build Path Problem

Unbound classpath variable: 'M2_REPO/junit/junit/3.8.2/junit-3.8.2.jar' in
project 'SnakeYAML' SnakeYAML Build path Build Path Problem

Unbound classpath variable:
'M2_REPO/org/springframework/spring/2.5.6/spring-2.5.6.jar' in project
'SnakeYAML SnakeYAML Build path Build Path Problem

What’s wrong?
It seems to be errors from SnakeYAML and not me or Eclipse!

I am working on WindowsVistaUltimateSP2-32-bit with Eclipse Galileo
Packages Eclipse Classic 3.5.1.

Thanks for help,
Rainer

Original issue reported on code.google.com by [email protected] on 16 Nov 2009 at 7:41

Autogenerated anchors fail sanity test

What steps will reproduce the problem?
1. Generate a YAML file with over a thousand anchors.

What is the expected output? What do you see instead?
I was expecting a YAML file; I saw an exception thrown from Emitter 
complaining that id4,123 was an invalid anchor.

What version of the product are you using? On what operating system?
SnakeYAML 1.5 on Ubuntu.

Please provide any additional information below.
Enclosed is a patch.

Original issue reported on code.google.com by [email protected] on 5 Dec 2009 at 1:27

Attachments:

Regression: cannot create JavaBean containing a custom element with more than one constructor

The following test fails for SnakeYAML 1.4-SNAPSHOT, but succeeds for
SnakeYAML 1.3:

It succeeds if you remove the 2nd constructor from class Custom.
Note that the direct creation of the object ("key3") works in 1.4-SNAP too.

import junit.framework.TestCase;

import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.error.YAMLException;
import org.yaml.snakeyaml.Loader;
import org.yaml.snakeyaml.Dumper;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.representer.Representer;
import org.yaml.snakeyaml.representer.Represent;
import org.yaml.snakeyaml.nodes.Node;
import org.yaml.snakeyaml.nodes.ScalarNode;
import org.yaml.snakeyaml.nodes.MappingNode;
import org.yaml.snakeyaml.constructor.Constructor;
import org.yaml.snakeyaml.constructor.Construct;
import org.yaml.snakeyaml.constructor.ConstructorException;

import java.io.*;
import java.util.*;

/**
** @author infinity0
*/
public class YamlMapTest extends TestCase {

    public void testYamlMap() throws IOException {
        Map<String, Object> data = new TreeMap<String, Object>();
        data.put("key3", new Custom("test"));
        data.put("key4", new Wrapper("test", new Custom("test")));

        Yaml yaml = new Yaml(new Loader(new ExtendedConstructor()),
                            new Dumper(new ExtendedRepresenter(), new DumperOptions()));
        File file = new File("beantest.yml");

        FileOutputStream os = new FileOutputStream(file);
        yaml.dump(data, new OutputStreamWriter(os));
        os.close();

        FileInputStream is = new FileInputStream(file);
        Object o = yaml.load(new InputStreamReader(is));
        is.close();

        assertTrue(o instanceof Map);
        Map m = (Map)o;
        assertTrue(m.get("key3") instanceof Custom);
        assertTrue(m.get("key4") instanceof Wrapper);
    }

    public static class Wrapper {
        private String a;
        private Custom b;
        public Wrapper(String s, Custom bb) { a = s; b = bb; }
        public Wrapper() { }
        public String getA() { return a; }
        public void setA(String s) { a = s; }
        public Custom getB() { return b; }
        public void setB(Custom bb) { b = bb; }
    }

    public static class Custom {
        final private String str;
        public Custom(String s) {
            str = s;
        }
        public Custom(Integer i) {
            str = "";
        }
        public Custom(Custom c) {
            str = c.str;
        }
        public String toString() { return str; }
    }


    public static class ExtendedRepresenter extends Representer {
        public ExtendedRepresenter() {
            this.representers.put(Custom.class, new RepresentCustom());
        }

        private class RepresentCustom implements Represent {
            @Override public Node representData(Object data) {
                return representScalar("!Custom", ((Custom) data).toString());
            }
        }
    }


    public static class ExtendedConstructor extends Constructor {
        public ExtendedConstructor() {
            this.yamlConstructors.put("!Custom", new ConstructCustom());
        }

        private class ConstructCustom implements Construct {
            @Override public Object construct(Node node) {
                String str = (String) constructScalar((ScalarNode)node);
                return new Custom(str);
            }
            @Override public void construct2ndStep(Node node, Object object) { }
        }
    }

}




error with 869:49ff0bdb91f8

    [junit] Testcase: testYamlMap took 0.097 sec
    [junit]     Caused an ERROR
    [junit] null; Can't construct a java object for
tag:yaml.org,2002:plugins.Library.serial.YamlMapTest$Wrapper;
exception=Cannot create property=b for
JavaBean=plugins.Library.serial.YamlMapTest$Wrapper@442a15cd; More then 1
constructor with 1 argument found for class
plugins.Library.serial.YamlMapTest$Custom
    [junit] Can't construct a java object for
tag:yaml.org,2002:plugins.Library.serial.YamlMapTest$Wrapper;
exception=Cannot create property=b for
JavaBean=plugins.Library.serial.YamlMapTest$Wrapper@442a15cd; More then 1
constructor with 1 argument found for class
plugins.Library.serial.YamlMapTest$Custom
    [junit]  in "<reader>", line 1, column 6
    [junit] 
    [junit]     at
org.yaml.snakeyaml.constructor.Constructor$ConstructYamlObject.construct(Constru
ctor.java:283)
    [junit]     at
org.yaml.snakeyaml.constructor.BaseConstructor.callConstructor(BaseConstructor.j
ava:172)
    [junit]     at
org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.j
ava:155)
    [junit]     at
org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping2ndStep(BaseConst
ructor.java:257)
    [junit]     at
org.yaml.snakeyaml.constructor.SafeConstructor.constructMapping2ndStep(SafeConst
ructor.java:112)
    [junit]     at
org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping(BaseConstructor.
java:238)
    [junit]     at
org.yaml.snakeyaml.constructor.SafeConstructor$ConstructYamlMap.construct(SafeCo
nstructor.java:433)
    [junit]     at
org.yaml.snakeyaml.constructor.BaseConstructor.callConstructor(BaseConstructor.j
ava:172)
    [junit]     at
org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.j
ava:155)
    [junit]     at
org.yaml.snakeyaml.constructor.BaseConstructor.constructDocument(BaseConstructor
.java:114)
    [junit]     at
org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.jav
a:100)
    [junit]     at org.yaml.snakeyaml.Loader.load(Loader.java:39)
    [junit]     at org.yaml.snakeyaml.Yaml.load(Yaml.java:164)
    [junit]     at
plugins.Library.serial.YamlMapTest.testYamlMap(YamlMapTest.java:47)
    [junit] Caused by: org.yaml.snakeyaml.error.YAMLException: Cannot
create property=b for
JavaBean=plugins.Library.serial.YamlMapTest$Wrapper@442a15cd; More then 1
constructor with 1 argument found for class
plugins.Library.serial.YamlMapTest$Custom
    [junit]     at
org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.constructJavaBean2nd
Step(Constructor.java:227)
    [junit]     at
org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.construct(Constructo
r.java:138)
    [junit]     at
org.yaml.snakeyaml.constructor.Constructor$ConstructYamlObject.construct(Constru
ctor.java:281)
    [junit] Caused by: org.yaml.snakeyaml.error.YAMLException: More then 1
constructor with 1 argument found for class
plugins.Library.serial.YamlMapTest$Custom
    [junit]     at
org.yaml.snakeyaml.constructor.Constructor$ConstructScalar.construct(Constructor
.java:318)
    [junit]     at
org.yaml.snakeyaml.constructor.BaseConstructor.callConstructor(BaseConstructor.j
ava:172)
    [junit]     at
org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.j
ava:155)
    [junit]     at
org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.constructJavaBean2nd
Step(Constructor.java:220)
    [junit] 



Original issue reported on code.google.com by [email protected] on 5 Aug 2009 at 9:11

Stream-like processing of YAML documents

Currently reading and writing a document in a stream like fassion only
works on the event layer. Nodes and Objects are processed one document at a
time. This is a problem for me as I have huge documents which I do not want
to have in memory at once.

I could use the events, but then I have to do all the remaining work by my
self. 

YAML has the nice property that a partially read document has a valid
structure. Maybe this can be exploited.


Original issue reported on code.google.com by [email protected] on 13 Nov 2009 at 5:05

GregorianCalendar should be output as regular Timestamp

GregorianCalendar recurses as a bean instead, and fails on load trying to build 
a timezone.


i.e.:

!!java.util.GregorianCalendar
  firstDayOfWeek: 1
  gregorianChange: 1582-10-15T00:00:00Z
  lenient: true
  minimalDaysInFirstWeek: 1
  time: 2009-11-06T00:10:04.373Z
  timeInMillis: 1257466204373

Since Gregorian Calendar is one of the official approved ways to store a 
date/time, this should 
work as any other Yaml date/time


Probably best to turn it into an ISO string instead. 

Original issue reported on code.google.com by [email protected] on 11 Feb 2010 at 10:03

Interface for constructing immutable objects

I thought you might find this interesting/useful. 

I recently created a class that lets you create a "blueprint" for an
object, which includes a way to deserialise objects via a single call to a
constructor.

http://github.com/freenet/plugin-Library-staging/blob/master/src/plugins/Library
/io/ObjectBlueprint.java

At the moment, I'm using it as an adapter between my code and SnakeYAML:

static ObjectBlueprint<MyClass> my_blueprint;
static {
    try {
        my_blueprint = new ObjectBlueprint<MyClass>(MyClass.class,
Arrays.asList("field1", "field2", "field3"));
    } catch (NoSuchFieldException e) {
        throw new AssertionError(e);
    } catch (NoSuchMethodException e) {
        throw new AssertionError(e);
    }
}

In a Represent:

public Node representData(Object data) {
    return representMapping("!MyClass",
my_blueprint.objectAsMap((MyClass)data), true);
}

In a Construct:

public Object construct(Node node) {
    MyClass my_object;
    try {
        my_object =
my_blueprint.objectFromMap((Map)constructMapping((MappingNode)node));
    } catch (Exception e) {
        //java.lang.InstantiationException
        //java.lang.IllegalArgumentException
        //java.lang.reflect.InvocationTargetException
        throw new ConstructorException(/* etc */);
    }
    return my_object;
}

This technically works, but I'm guessing is inefficient, because it uses
that intermediate map.

Maybe you could extend this blueprint class and integrate it into
SnakeYAML, so that this process can happen more directly? It would then
give a nice interface to define how to construct/represent immutable objects.

Original issue reported on code.google.com by [email protected] on 22 Aug 2009 at 5:07

Unable to dump JavaBean that inherits from a protected base class

What steps will reproduce the problem?
The following Java program will reproduce the problem:

package sf.snakeyaml_test;

import org.yaml.snakeyaml.Yaml;

public class SnakeyamlTest
{

  public static interface SomeBean
  {

    String getAttribute1();

    String getAttribute2();
  }

  /*public */static abstract class BaseSomeBean
      implements SomeBean
  {

    private String attribute1;

    public final String getAttribute1()
    {
      return attribute1;
    }

    public final void setAttribute1(String attribute1)
    {
      this.attribute1 = attribute1;
    }

  }

  public static final class SomeBeanImpl
      extends BaseSomeBean
  {

    private String attribute2;

    public SomeBeanImpl(final String attribute1, final String attribute2)
    {
      setAttribute1(attribute1);
      setAttribute2(attribute2);
    }

    public String getAttribute2()
    {
      return attribute2;
    }

    public void setAttribute2(String attribute2)
    {
      this.attribute2 = attribute2;
    }

  }

  public static void main(String[] args)
  {
    final SomeBean someBean = new SomeBeanImpl("value1", "value2");
    final Yaml dumper = new Yaml();
    // final JavaBeanDumper dumper = new JavaBeanDumper();
    final String output = dumper.dump(someBean);
    System.out.println(output);
  }

}


What is the expected output? What do you see instead?
Expected output:
!!sf.snakeyaml_test.SnakeyamlTest$SomeBeanImpl {attribute1: value1,
attribute2: value2}

What I get instead:
Exception in thread "main" org.yaml.snakeyaml.error.YAMLException: Unable
to find getter for property 'attribute1' on object
sf.snakeyaml_test.SnakeyamlTest$SomeBeanImpl@c1b531:java.lang.IllegalAccessExcep
tion:
Class org.yaml.snakeyaml.introspector.MethodProperty can not access a
member of class sf.snakeyaml_test.SnakeyamlTest$BaseSomeBean with modifiers
"public final"
    at org.yaml.snakeyaml.introspector.MethodProperty.get(MethodProperty.java:62)
    at
org.yaml.snakeyaml.representer.Representer.representJavaBean(Representer.java:97
)
    at
org.yaml.snakeyaml.representer.Representer$RepresentJavaBean.representData(Repre
senter.java:67)
    at
org.yaml.snakeyaml.representer.BaseRepresenter.representData(BaseRepresenter.jav
a:107)
    at
org.yaml.snakeyaml.representer.BaseRepresenter.represent(BaseRepresenter.java:60
)
    at org.yaml.snakeyaml.Dumper.dump(Dumper.java:51)
    at org.yaml.snakeyaml.Yaml.dumpAll(Yaml.java:140)
    at org.yaml.snakeyaml.Yaml.dumpAll(Yaml.java:113)
    at org.yaml.snakeyaml.Yaml.dump(Yaml.java:101)
    at sf.snakeyaml_test.SnakeyamlTest.main(SnakeyamlTest.java:63)


What version of the product are you using? On what operating system?
snakeyaml 1.5 on Windows XP SP3, with Sun JDK 1.5.0_14




Original issue reported on code.google.com by [email protected] on 12 Feb 2010 at 4:04

Load failures for array type fields

How do you load objects that have arrays as fields? This example below
fails to load. But the dump() succeeds.

<code>
public class Temp {
    public static void main(String[] args) {
        A a = new A();
        a.setNames(new String[]{"a", "b", "c"});

        Yaml yaml = new Yaml();
        String s = yaml.dump(a);
        System.out.println(s);

        Object result = yaml.load(s);
        System.out.println(result);
    }

    public static class A {
        String[] names;

        public String[] getNames() {
            return names;
        }

        public void setNames(String[] names) {
            this.names = names;
        }

        public String getName(int index) {
            return names[index];
        }

        public void setName(int index, String name) {
            this.names[index] = name;
        }
    }
}
</code>

Error:
<code>
Exception in thread "main" Can't construct a java object for
tag:yaml.org,2002:test.Temp$A; exception=Cannot create property=names for
JavaBean=test.Temp$A@b8f82d; argument type mismatch
 in "<reader>", line 0, column 0

    at
org.yaml.snakeyaml.constructor.Constructor$ConstructYamlObject.construct(Constru
ctor.java:283)
    at
org.yaml.snakeyaml.constructor.BaseConstructor.callConstructor(BaseConstructor.j
ava:175)
    at
org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.j
ava:158)
    at
org.yaml.snakeyaml.constructor.BaseConstructor.constructDocument(BaseConstructor
.java:117)
    at
org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.jav
a:103)
    at org.yaml.snakeyaml.Loader.load(Loader.java:39)
    at org.yaml.snakeyaml.Yaml.load(Yaml.java:140)
    at test.Temp.main(Temp.java:17)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.jav
a:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
Caused by: org.yaml.snakeyaml.error.YAMLException: Cannot create
property=names for JavaBean=test.Temp$A@b8f82d; argument type mismatch
    at
org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.constructJavaBean2nd
Step(Constructor.java:227)
    at
org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.construct(Constructo
r.java:138)
    at
org.yaml.snakeyaml.constructor.Constructor$ConstructYamlObject.construct(Constru
ctor.java:281)
    ... 12 more
Caused by: java.lang.IllegalArgumentException: argument type mismatch
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.jav
a:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.yaml.snakeyaml.introspector.MethodProperty.set(MethodProperty.java:20)
    at
org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.constructJavaBean2nd
Step(Constructor.java:225)
    ... 14 more
</code>

Original issue reported on code.google.com by [email protected] on 18 Sep 2009 at 10:08

LinkedList is inefficient for iteration

ArrayList is more efficient than LinkedList if you just want to create a
collection and iterate through it.

http://soft.killingar.net/documents/LinkedList+vs+ArrayList

In summary, LinkedList should *only* be used when you need to do lots of
inserts and deletions in the *middle* of the list.

Original issue reported on code.google.com by [email protected] on 21 Aug 2009 at 12:04

support partial representation when document contains unrecognized tags

Please support loading documents with unrecognized tags, either by default or 
as an option that 
can be turned on when constructing a new Yaml instance. This is similar to 
[Issue 31][1].

Steps to Reproduce
1. generate a YAML document containing application specific tags
2. construct a YAML instance with default constructor only
3. attempt to load the document
4. load will fail with an error

Expected Output:
I would prefer that SnakeYAML will load the document as a [partial 
representation][2] per the 
spec, using the node's kind to resolve it as seq, map, or str as appropriate.

Actual Output:

An error:
    The document is not valid YAML:
    could not determine a constructor for the tag '...'
    ...

What version of the product are you using? On what operating system?
SnakeYAML-1.2, OS X 10.6.1 and CenOS Linux


[1] http://code.google.com/p/snakeyaml/issues/detail?id=31
[2] http://yaml.org/spec/1.1/#partial%20representation/

Original issue reported on code.google.com by [email protected] on 8 Dec 2009 at 1:22

extra braces while dumping map data as yaml

What steps will reproduce the problem?
1. Running the following program 

    Map<String, Object> data = new HashMap<String, Object>();
    data.put("name", "Silenthand Olleander");
    data.put("race", "Human");
    data.put("race1", "0.001");
    // data.put("traits", new String[] { "ONE_HAND", "ONE_EYE" });

    Yaml yaml = new Yaml();
    String output = yaml.dump(data);
    System.out.println(output);

Output1 is "{race1: '0.001', race: Human, name: Silenthand Olleander}"
2.
    Map<String, Object> data = new HashMap<String, Object>();
    data.put("name", "Silenthand Olleander");
    data.put("race", "Human");
    data.put("race1", "0.001");
    data.put("traits", new String[] { "ONE_HAND", "ONE_EYE" });

    Yaml yaml = new Yaml();
    String output = yaml.dump(data);
    System.out.println(output);

OutPut2 is "
traits: [ONE_HAND, ONE_EYE]
race1: '0.001'
race: Human
name: Silenthand Olleander"


What is the expected output? What do you see instead?
Why output1 has braces ? If i have to remove braces then i have to add 
the  following in data

    data.put("traits", new String[] { "ONE_HAND", "ONE_EYE" });


What version of the product are you using? On what operating system?

Windows XP , Java - 1.5.10 , Snake Yaml Version  - snake yaml 1.0
Please provide any additional information below.


Original issue reported on code.google.com by [email protected] on 3 Dec 2009 at 8:55

introduce Tag class

Currently (version 1.5) SnakeYAML is using simple Strings to represent tags.
Even though it works it would be more flexible and safe to introduce a 
special class for tags.

Original issue reported on code.google.com by [email protected] on 11 Jan 2010 at 8:45

Providing Construct/Representer logic within the Class

If the defaults are not enough, I have to write a Construct and a
Representer class. Sometimes it would be nice to have everything in one
class. Especially if only a few lines of code are requried.

This could look like this:

public class MyDataObj{

    ...
    ...

    @YAMLConstruct
    public static MyDataObj construct(Node node){
        ...
    }

    @YAMLRepresent
    public Node represent(){
        ...
    }
}

It would be even better if snakeyaml would automatically recognize the
annotations, such that no explicit registration is required. 

Original issue reported on code.google.com by [email protected] on 13 Nov 2009 at 5:21

IllegalArgumentException thrown when attempting to set BigDecimal property

What steps will reproduce the problem?
1. Create a bean instance that has a BigDecimal property.
2. Set the BigDecimal property to a non-decimal value, i.e. "5".
3. Create a default Yaml and dump the bean to a String.
4. Attempt to load a new bean instance from the String.

What is the expected output? What do you see instead?

Yaml should return a new instance of a Bean that has an identical
BigDecimal value on the set property.

Instead this exception is thrown:

Can't construct a java object for
tag:yaml.org,2002:<*removed*>.DogFoodBean; exception=Cannot create
property=decimal for JavaBean=<*removed*>.DogFoodBean@c3c749; argument type
mismatch
 in "<reader>", line 0, column 0

    at
org.yaml.snakeyaml.constructor.Constructor$ConstructYamlObject.construct(Constru
ctor.java:295)
    at
org.yaml.snakeyaml.constructor.BaseConstructor.callConstructor(BaseConstructor.j
ava:187)
    at
org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.j
ava:170)
    at
org.yaml.snakeyaml.constructor.BaseConstructor.constructDocument(BaseConstructor
.java:129)
    at
org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.jav
a:115)
    at org.yaml.snakeyaml.Loader.load(Loader.java:51)
    at org.yaml.snakeyaml.Yaml.load(Yaml.java:152)
    at <*removed*>.DogFoodTest.testOwnBigDecimal(DogFoodTest.java:20)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.jav
a:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)
    at org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)
    at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
    at
org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadi
e.java:87)
    at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
    at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
    at
org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.
java:88)
    at
org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:5
1)
    at
org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
    at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
    at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
    at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
    at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReferen
ce.java:45)
    at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner
.java:460)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner
.java:673)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java
:386)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.jav
a:196)
Caused by: org.yaml.snakeyaml.error.YAMLException: Cannot create
property=decimal for JavaBean=<*removed*>.DogFoodBean@c3c749; argument type
mismatch
    at
org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.constructJavaBean2nd
Step(Constructor.java:239)
    at
org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.construct(Constructo
r.java:150)
    at
org.yaml.snakeyaml.constructor.Constructor$ConstructYamlObject.construct(Constru
ctor.java:293)
    ... 29 more
Caused by: java.lang.IllegalArgumentException: argument type mismatch
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.jav
a:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.yaml.snakeyaml.introspector.MethodProperty.set(MethodProperty.java:32)
    at
org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.constructJavaBean2nd
Step(Constructor.java:237)
    ... 31 more



What version of the product are you using? On what operating system?

Version 1.4, Windows XP Professional, Java 1.6

Please provide any additional information below.

Test Code:

import java.math.BigDecimal;

//SnakeYaml should be able to eat its own dog-food (load its own output).
public class DogFoodBean{

    BigDecimal decimal;

    public DogFoodBean(){
        decimal = BigDecimal.ZERO;
    }

    public BigDecimal getDecimal(){
        return decimal;
    }

    public void setDecimal(BigDecimal decimal){
        this.decimal = decimal;
    }   

}


import static org.junit.Assert.assertEquals;

import java.math.BigDecimal;

import org.junit.Test;
import org.yaml.snakeyaml.Yaml;


public class DogFoodTest {

    @Test
    public void testOwnBigDecimal(){
        DogFoodBean input = new DogFoodBean();
        input.setDecimal(new BigDecimal("5"));      
        Yaml yaml = new Yaml();
        String text = yaml.dump(input);
        DogFoodBean output = (DogFoodBean) yaml.load(text);
        assertEquals(output.getDecimal(), input.getDecimal());
    }

}



Original issue reported on code.google.com by [email protected] on 31 Dec 2009 at 7:08

Introduce multi contructors (tag prefix)

At the moment SnakeYAML always tries to match the complete tag to 
construct an instance. 
It shall be possible to define the beginning of the tag (tag prefix)? 
Then for these 2 tags: 
!!org.foo.Bar111 
!!org.foo.Bar222 
it should be possible to define a constructor with tag prefix "!! 
org.foo". 
Then a constructor may process a family of tags.
The prefix is only checked when no exact match found.

Original issue reported on code.google.com by [email protected] on 25 Nov 2009 at 8:53

Typed setters for the entities

Не знаю, баг это или фича, но мне очень не 
нравится, что SnakeYAML 
вмешивается во внутреннюю логику 
сущностей.

Допустим есть класс:

<code>
class Entity {
    private int id;

    public Entity setId( int id ) {
       this.id = id;
       return this;
    }
}
</code>

Если написать фикстуры и попытаться 
синтезировать объект для данной 
сущности, мы получим ошибку о том, что поле 
`id` не было найдено. В тоже 
время при возвращаемом *setId* типе *void* - всё 
работает замечательно.

Original issue reported on code.google.com by LoRd1990 on 20 Jan 2010 at 2:25

Sorting of fields in the dump() output

This is only a suggestion, not a bug. It would be very nice if we had an
option to not sort the fields, but just print it in the order it appears in
the Java Class. It's more readable that way.

Keep up the good work!

Ashwin.

Original issue reported on code.google.com by [email protected] on 18 Sep 2009 at 10:34

Not enough examples for Loading

What is the reverse of the Dumper + Representer feature?

When you tag a class using,
        Representer representer = new Representer();
        representer.addClassTag(Definition.class, "define");

What do we use for Loading the same? The parser complains of unrecognized
"!<define>" characters.

Nice work on SnakeYaml, but some better docs on Loading would be appreciated.

Thanks!
Ashwin.


Original issue reported on code.google.com by [email protected] on 18 Sep 2009 at 10:12

JavaBeans constructor/representer could be more efficient

In Representer.java, it looks as though a new Set<Property> is created for
each instance of a bean, instead of for each *type* of bean.

In Constructor.java, it's even worse, a Property is obtained by iterating
through the fields/methods of a JavaBean, for each property, for each
instance of the bean.

Ideally, you would create some sort of blueprint for each new *type* (ie.
class) of JavaBean you come across. The blueprint might store a Map<String,
Property> (or something), then have methods to construct/represent a given
instance of the JavaBean, something like the ObjectBlueprint class I linked
to in issue#15. 

Original issue reported on code.google.com by [email protected] on 22 Aug 2009 at 5:10

Please set the "cause" field for MarkedYAMLException

What steps will reproduce the problem?

class Bean {
  String a = null;
  public Bean() {}
  public String getA() { return a; }
  public void setA(String s) { a = s.intern(); }
}

If we dump just new Bean() without setting a, and then try to load it, we
get the cryptic error message

Can't construct a java object for tag:[TAG];
exception=java.lang.reflect.InvocationTargetException

This is because in constructor.Constructor.java, in
ConstructYamlObject.construct(), you catch (Exception e), but you discard
all the information in this exception, instead only adding e.getMessage()
to the new exception's message. 

You should make the constructor of MarkedYAMLException accept the standard
"Throwable cause" argument of all Throwables, then we can call
printStackTrace() on that exception to get a more meaningful error message,
something like this:

    [junit] org.yaml.snakeyaml.error.YAMLException:
java.lang.reflect.InvocationTargetException
    [junit]     at
org.yaml.snakeyaml.constructor.Constructor.constructMappingNode2ndStep(Construct
or.java:394)
    [junit]     at
org.yaml.snakeyaml.constructor.Constructor.constructMappingNode(Constructor.java
:341)
    [junit]     at
org.yaml.snakeyaml.constructor.Constructor.access$200(Constructor.java:33)
    [junit]     at
org.yaml.snakeyaml.constructor.Constructor$ConstructYamlObject.construct(Constru
ctor.java:108)
    [junit]     at
org.yaml.snakeyaml.constructor.BaseConstructor.callConstructor(BaseConstructor.j
ava:117)
    [junit]     at
org.yaml.snakeyaml.constructor.Constructor.callConstructor(Constructor.java:157)
    [junit]     at
org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.j
ava:107)
    [junit]     at
org.yaml.snakeyaml.constructor.BaseConstructor.constructSequenceStep2(BaseConstr
uctor.java:148)
    [junit]     at
org.yaml.snakeyaml.constructor.BaseConstructor.constructSequence(BaseConstructor
.java:142)
    [junit]     at
org.yaml.snakeyaml.constructor.SafeConstructor$ConstructYamlSeq.construct(SafeCo
nstructor.java:404)
    [junit]     at
org.yaml.snakeyaml.constructor.BaseConstructor.callConstructor(BaseConstructor.j
ava:117)
    [junit]     at
org.yaml.snakeyaml.constructor.Constructor.callConstructor(Constructor.java:157)
    [junit]     at
org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.j
ava:107)
    [junit]     at
org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping2ndStep(BaseConst
ructor.java:189)
    [junit]     at
org.yaml.snakeyaml.constructor.SafeConstructor.constructMapping2ndStep(SafeConst
ructor.java:104)
    [junit]     at
org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping(BaseConstructor.
java:170)
    [junit]     at
org.yaml.snakeyaml.constructor.SafeConstructor$ConstructYamlMap.construct(SafeCo
nstructor.java:423)
    [junit]     at
org.yaml.snakeyaml.constructor.BaseConstructor.callConstructor(BaseConstructor.j
ava:117)
    [junit]     at
org.yaml.snakeyaml.constructor.Constructor.callConstructor(Constructor.java:157)
    [junit]     at
org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.j
ava:107)
    [junit]     at
org.yaml.snakeyaml.constructor.BaseConstructor.constructDocument(BaseConstructor
.java:74)
    [junit]     at
org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.jav
a:68)
    [junit]     at org.yaml.snakeyaml.Loader.load(Loader.java:39)
    [junit]     at org.yaml.snakeyaml.Yaml.load(Yaml.java:164)
    [junit]     at plugins.Interdex.serl.YamlArchiver.pull(YamlArchiver.java:79)
    [junit]     at
plugins.Interdex.index.TokenEntryTest.testBasic(TokenEntryTest.java:57)
    [junit]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    [junit]     at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    [junit]     at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.jav
a:43)
    [junit]     at java.lang.reflect.Method.invoke(Method.java:616)
    [junit]     at junit.framework.TestCase.runTest(TestCase.java:164)
    [junit]     at junit.framework.TestCase.runBare(TestCase.java:130)
    [junit]     at junit.framework.TestResult$1.protect(TestResult.java:106)
    [junit]     at junit.framework.TestResult.runProtected(TestResult.java:124)
    [junit]     at junit.framework.TestResult.run(TestResult.java:109)
    [junit]     at junit.framework.TestCase.run(TestCase.java:120)
    [junit]     at junit.framework.TestSuite.runTest(TestSuite.java:230)
    [junit]     at junit.framework.TestSuite.run(TestSuite.java:225)
    [junit]     at
org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:91)
    [junit]     at
junit.framework.JUnit4TestAdapter.run(JUnit4TestAdapter.java:39)
    [junit]     at
org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner
.java:421)
    [junit]     at
org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRun
ner.java:912)
    [junit]     at
org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunne
r.java:766)
    [junit] Caused by: java.lang.reflect.InvocationTargetException
    [junit]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    [junit]     at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    [junit]     at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.jav
a:43)
    [junit]     at java.lang.reflect.Method.invoke(Method.java:616)
    [junit]     at
org.yaml.snakeyaml.introspector.MethodProperty.set(MethodProperty.java:20)
    [junit]     at
org.yaml.snakeyaml.constructor.Constructor.constructMappingNode2ndStep(Construct
or.java:392)
    [junit]     ... 42 more
    [junit] Caused by: java.lang.NullPointerException
    [junit]     at Bean.setA(Bean.java:5)
    [junit]     ... 48 more


which helps the user track down what's causing the error.

As applied to the example code, this error trace now helps us to track down
what's causing YAML to throw the exception - since we don't setA() before
dumping, a is set to null, and when the YAML constructor comes to loading
it, it will call setA(null), giving a NullPointerException when we try to
do null.intern().

Original issue reported on code.google.com by [email protected] on 9 Jul 2009 at 8:28

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.