Closed GoogleCodeExporter closed 9 years ago
Please provide more information.
Just looking in the example gives the impression that SnakeYAML has nothing to
do with the problem because the exception occurs when you put an object to a
Map.
Does the problem occur when you dump ?
Can you please provide a failing test? (SnankeYAML has a lot of examples with
Map and custom objects. See the tests.
Original comment by py4fun@gmail.com
on 14 Sep 2011 at 10:03
Hello. I've seen all examples.
> Does the problem occur when you dump ?
Yes.
Here is a test:
<code>
public void snakeyaml() {
Yaml yaml = new Yaml();
HashMap<String, Object> m = new HashMap<String, Object>();
m.put("i", 1234);//works fine
m.put("b", false);//works fine
m.put("s", "text");//works fine
m.put("l", new Point());//Will be Exception java.lang.StackOverflowError on DUMPING
//m.put("l", new AnotherObject());//I want to use another objects to dump/load
System.out.println(yaml.dump(m));
}
</code>
Original comment by GZe...@gmail.com
on 15 Sep 2011 at 6:39
Test is the best way to explain your idea. It is not clear that Point is
actually java.awt.Point (because AnotherObject is obviously not
java.awt.AnotherObject).
Now I see the problem. The stackoverflow happens because Point creates a new
instance in the method 'getLocation()'. SnakeYAML works properly with recursive
structures but it cannot prevent this case.
One of the possible solutions may be to skip the 'location' property when
dumping.
I have put the complete solution to the tests:
http://code.google.com/p/snakeyaml/source/browse/src/test/java/org/yaml/snakeyam
l/issues/issue133/StackOverflowTest.java
There is also a brief description how to skip a JavaBean property:
http://code.google.com/p/snakeyaml/wiki/howto#How_to_skip_a_JavaBean_property
Original comment by py4fun@gmail.com
on 15 Sep 2011 at 8:46
Hello.
Thanks for answer and sorry for my bad code without import "java.awt."
package...
> One of the possible solutions may be to skip the 'location' property when
dumping.
I think, i will change "Point" for int.x and int.y variables, because I dont
want to use custom representer.
> SnakeYAML works properly with recursive structures but it cannot prevent this
case.
Will this feature be added to SnakeYAML?
Thanks a lot again!
Original comment by GZe...@gmail.com
on 15 Sep 2011 at 6:01
You are welcome!
It cannot be added as a feature. It is the same as if there is an exception
when you get a value. It can only be solved on the application level.
Original comment by py4fun@gmail.com
on 15 Sep 2011 at 8:04
Original issue reported on code.google.com by
GZe...@gmail.com
on 14 Sep 2011 at 8:31