float primitives with CompactConstructor

19 views
Skip to first unread message

Tommy Odom

unread,
Mar 7, 2012, 9:42:52 AM3/7/12
to snakeya...@googlegroups.com
I was attempting to use the CompactConstructor but I ran into a problem with float primitives.  With the CompactConstructor the float scalars seem to always get created as Doubles which then throws an IllegalArgumentException when the property is set.  As a test I modified the examples12.yaml to set a float primitive that I added to the Row test class and it also failed the same way.  Am I doing something wrong?

Andrey

unread,
Mar 10, 2012, 7:06:03 AM3/10/12
to snakeya...@googlegroups.com
Hi,
see the reply here:
http://code.google.com/p/snakeyaml/issues/detail?id=144



On Wednesday, March 7, 2012 3:42:52 PM UTC+1, Tommy Odom wrote:
I was attempting to use the CompactConstructor but I ran into a problem with float primitives.  With the CompactConstructor the float scalars seem to always get created as Doubles which then throws an IllegalArgumentException when the property is set.  As a test I modified the examples12.yaml to set a float primitive that I added to the Row test class and it also failed the same way.  Am I doing something wrong?

Andrey

unread,
Mar 12, 2012, 5:56:44 PM3/12/12
to snakeya...@googlegroups.com

Hi,
does the solution in the issue help you to resolve the problem ?

Andrey


On Wednesday, March 7, 2012 3:42:52 PM UTC+1, Tommy Odom wrote:

Tommy Odom

unread,
Mar 13, 2012, 8:30:48 AM3/13/12
to snakeya...@googlegroups.com
Hi thanks for the response.  I was actually starting down the path of doing custom type conversion within the setProperties method when you posted the response.  I was thinking that I could override the behavior of the CompactConstructor to create scalars as Strings (to avoid loss of precision for BigDecimal) and then in the setProperties convert to the correct type.  I was going to try to re-use the existing scalar constructor but the setProperties doesn't have access to the nodes.

I actually ended up using Spring XMLs instead of YAML files since we already depend on Spring.  The XMLs are obviously much more verbose than YAML but I can do a lot with them for data creation.

maslovalex

unread,
Mar 16, 2012, 7:15:48 PM3/16/12
to snakeya...@googlegroups.com
Hi Tommy !

If you still interested and willing to try... I fixed few things in CompactConstructor so that for properties defined in mapping we are not using implicit types.
Actually now CompactNotationObjects are less different from any other JavaBean SnakeYAML can load.
I think your example should work without any modifications of SnakeYAML's code.

Unfortunately values specified between (...) can only be strings.
Of course for those ones you can do some magic in setProperties... ;)

-alex

Tommy Odom

unread,
Mar 20, 2012, 12:38:47 PM3/20/12
to snakeya...@googlegroups.com
Hi thanks for working on that, that was really fast.  I'll definitely take a look at it when I get some time.
Reply all
Reply to author
Forward
0 new messages