ilmoeuro / snakeyaml

Automatically exported from code.google.com/p/snakeyaml
0 stars 0 forks source link

Bean with no property cannot be instantiated #9

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
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 wwagn...@gmail.com on 22 Jul 2009 at 7:53

Attachments:

GoogleCodeExporter commented 9 years ago
Thank you.
This is in fact not a bug but a feature request. Because {} are not used for 
the leaf 
bean SnakeYAML tries to construct a scalar. Since there is no single-argument 
(the 
empty String as the argument) constructor it fails. Nevertheless this is an 
interesting 
case. I will think how we can improve the implementation.

Original comment by py4fun@gmail.com on 24 Jul 2009 at 9:13

GoogleCodeExporter commented 9 years ago
Question: if a Java instance is created out of following YAML document: 

"!!com.package.Name" and 2 constructors are present in the Name class: 
no-argument 
constructor and with a String argument which constructor shall be used and why ?

Current situation:

"!!com.package.Name {}" - empty constructor is called

"!!com.package.Name" - constructor with an empty String is called

Original comment by py4fun@gmail.com on 27 Jul 2009 at 8:42

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Fixed.

Take the latest source and check:
`http://code.google.com/p/snakeyaml/source/browse/src/test/java/org/yaml/snakeya
ml/issu
es/issue9/NopropTest.java`

The support is done via a custom Constructor (BeanConstructor). We need that 
because 
there is more then 1 way to create an instance.

Original comment by py4fun@gmail.com on 5 Aug 2009 at 7:54

GoogleCodeExporter commented 9 years ago

Original comment by aso...@gmail.com on 6 Aug 2009 at 10:00