UcasRichard / snakeyaml

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

I cannot deserialise into a Vector object. #17

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
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 jcucur...@gmail.com on 3 Sep 2009 at 11:04

Attachments:

GoogleCodeExporter commented 9 years ago
As it is indicated in the JavaDoc the argument for the Constructor is the 
"fully 
qualified class name of the root JavaBean". Since Vector is not a JavaBean this 
is 
simply ignored.
You can do the following:
- when you have Java on both sides extend Representer to issue global tags with 
class 
names
- if you always use only one implementation change default sequence 
implementation
(http://code.google.com/p/snakeyaml/source/browse/src/test/java/examples/CustomL
istEx
ampleTest.java)
In the meantime I will try to improve the situation.

Original comment by py4fun@gmail.com on 3 Sep 2009 at 2:58

GoogleCodeExporter commented 9 years ago
Fixed. Check the test:

http://code.google.com/p/snakeyaml/source/browse/src/test/java/org/yaml/snakeyam
l/const
ructor/VectorTest.java

Thanks for your input.

Original comment by py4fun@gmail.com on 4 Sep 2009 at 7:43

GoogleCodeExporter commented 9 years ago
The issue has been fixed, I can serialise and deserialise the Vector in the 
test. 

Nevertheless, within the context of my application a new error has appeared, in 
this
case within the serialisation process: 

org.yaml.snakeyaml.error.YAMLException: No JavaBean properties found in
java.util.AbstractList$Itr. 

I will try to find the cause in the application to make a piece of code to 
reproduce
the error. Then I will open a new issue. Thanks!

Original comment by jcucur...@gmail.com on 4 Sep 2009 at 9:31

GoogleCodeExporter commented 9 years ago
I think I know what is the new problem: you use the same Yaml instance to 
serialise and 
deserialise. Because you provided the root tag the Yaml instance tries to find 
and serialise JavaBean properties.
The solution may be simply create another Yaml instance. It should properly 
recognise 
the object as a List.

Original comment by py4fun@gmail.com on 4 Sep 2009 at 9:53