How to read a double instead of a float?

98 views
Skip to first unread message

franco graziosi

unread,
Feb 15, 2012, 5:12:33 PM2/15/12
to SnakeYAML
Hi,

It is not very clear to me how to change implicit types. I see how to
avoid them (in common tasks - just comment out), but it is possible to
change them, specifically I would like floating point numbers be
returned as double instead if float, and possibly, if followed by '%'
divided by 100.

Is there some simple example to do this, or something similar?

Thanks,

franco

Andrey

unread,
Feb 16, 2012, 3:36:00 AM2/16/12
to snakeya...@googlegroups.com
Hello,

the procedure:

1) instruct SnakeYAML that a scalar which matches a specific regular expression shall use your specific tag

\d+% -> !my_divided_float

2) instruct SnakeYAML how to create your business object (float) from the scalar (String) with the specific tag

You may find more info in the documentation:

Search tests for method "Yaml.addImplicitResolver(String tag, Pattern regexp, String first)" to see more examples.

I think, this is similar to what what you want to achieve:


Cheers,
-
Andrey
Reply all
Reply to author
Forward
0 new messages