youxinren / snakeyaml

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

[Patch] Improved support for parametarized types in collections #112

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Snakeyaml wasn't picking up the Class of parameterized types when they were in 
collections.

This patch should fix that.

What version of SnakeYAML are you using?
1.8, should still apply to HEAD

Original issue reported on code.google.com by Letharg...@gmail.com on 8 Mar 2011 at 3:47

Attachments:

GoogleCodeExporter commented 9 years ago
Since the problem is not very clear can you please provide a test which fails 
without the patch and succeeds with the patch ?

Original comment by py4fun@gmail.com on 8 Mar 2011 at 10:44

GoogleCodeExporter commented 9 years ago
you are right if Collection has another GenericType as a Parameter snakeYAML 
does returns nothing now during type discovery, so it will emit explicit tags 
and if there are no explicit tags in input document it will not load it 
correctly.
In your case it may be collection inside collection when you expect collection 
of some beans (objects).

There is actually another problem (I can imaging now) - if one of the Map's 
parameters is GenericType non of two is identified.

Would actually RawType help us? Not sure now why I did skip that step during 
GenericProperty writing (maybe just forgot :))

But test case would be really nice. Would it be too difficult to provide one?

Original comment by alexande...@gmail.com on 9 Mar 2011 at 7:08

GoogleCodeExporter commented 9 years ago
I've not got time to write a test right now, but I can link you to code where 
I'm using it.

https://github.com/leth/AllocationCurve/blob/master/src/main/java/uk/co/marcusco
bden/allocationcurve/yaml/FactoryConstructor.java

Snakeyaml was having problems identifying a parameterised class from within a 
parametrised collection.

Since parametrised Classes can't be instantiated directly I've overridden the 
Constructor class to call a factory-type method for that specific type.

Original comment by Letharg...@gmail.com on 11 Apr 2011 at 5:01

GoogleCodeExporter commented 9 years ago
I think this issue may also be solved as part of the fix for issue 115:
http://code.google.com/p/snakeyaml/wiki/changes

Can you please test it now against the latest 1.9-SNAPSHOT ?

Original comment by py4fun@gmail.com on 24 May 2011 at 8:45

GoogleCodeExporter commented 9 years ago
Nope it doesn't seem to be fixed.

Here's a testcase project against 1.9-SNAPSHOT.

I've included the snakeyaml class with my patch applied, so that the test 
passes.

Original comment by Letharg...@gmail.com on 25 May 2011 at 1:21

Attachments:

GoogleCodeExporter commented 9 years ago
Thank you very much.
Your patch has been accepted:
http://code.google.com/p/snakeyaml/source/detail?r=43286b9a042da1b64f396e3978104
8765e126410

Feel free to test the snapshot.

Original comment by py4fun@gmail.com on 25 May 2011 at 3:52

GoogleCodeExporter commented 9 years ago
I have added more tests and I am a bit confused with the result. Can you please 
get the source and uncomment the lines ? (it looks like the 'name' property is 
not created)

http://code.google.com/p/snakeyaml/source/detail?r=e833b8e1e6fca3300c22f6dfec422
f1319a3b2e3

(dumping of the object does not have to work. This is just a try. We can make 
it later as part of another issue)

Original comment by py4fun@gmail.com on 25 May 2011 at 4:43

GoogleCodeExporter commented 9 years ago
I'll give it a go tomorrow, but I'm not 100% certain that I've done the right 
thing in `MyYAMLConstructor'. That might be what's causing the name attribute 
not to be set.

Original comment by Letharg...@gmail.com on 25 May 2011 at 5:26

GoogleCodeExporter commented 9 years ago
Yes, I have just removed MyYAMLConstructor and the tests work.

If the snapshot works for you we can close the issue.

Original comment by py4fun@gmail.com on 26 May 2011 at 9:12

GoogleCodeExporter commented 9 years ago
Sorry I'm new to maven and I have no idea how to get it to update the snapshot, 
nor how to tell if it's actually done so.

Any pointers? (Either eclipse or the command line will do, or even both) ;)

Original comment by Letharg...@gmail.com on 26 May 2011 at 3:08

GoogleCodeExporter commented 9 years ago
If you refer to the snapshot in your project:
  <dependency>
    <groupId>org.yaml</groupId>
    <artifactId>snakeyaml</artifactId>
    <version>1.9-SNAPSHOT</version>
  </dependency>

then 'mvn test' is enough to download and run against the latest snapshot. But 
it is only helpful if your project is using Maven.
You can always get the latest source and run your application (or test) against 
the latest source. What ever is easier for you.
The goal is not to test the snapshot but to confirm the fix and give the green 
light to close the issue.

Original comment by py4fun@gmail.com on 26 May 2011 at 4:12

GoogleCodeExporter commented 9 years ago
You can also just download the snapshot from Sonatype manually 
(https://oss.sonatype.org/content/groups/public/org/yaml/snakeyaml/1.9-SNAPSHOT/
)

Put it to your classpath and test.

Original comment by py4fun@gmail.com on 27 May 2011 at 3:32

GoogleCodeExporter commented 9 years ago
Thanks for the link. The tests pass with the fix, and my original project now 
works with the snapshot too.

Feel free to close the issue :)

Original comment by Letharg...@gmail.com on 27 May 2011 at 6:08

GoogleCodeExporter commented 9 years ago
It will be delevered in release 1.9
http://code.google.com/p/snakeyaml/wiki/changes

Original comment by py4fun@gmail.com on 29 May 2011 at 10:37