putting a long instead of an int in a map

385 views
Skip to first unread message

Malte....@de.equens.com

unread,
Oct 31, 2011, 10:10:12 AM10/31/11
to snakeya...@googlegroups.com

 

 

Hi to all,

I seem to have some incompatibility using a simple number in my yaml

 

2011-10-31 14:43:26,283 ERROR [main] de.equens.filedemon.FileDemonExceptionHandler: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Long

java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Long

finishFileAllMinutes:           60

 

I also tried things like this

 

finishFileAllMinutes:           !!long 60

getting the same conflict

and

finishFileAllMinutes:           !!Long 60

 

getting

org.yaml.snakeyaml.error.YAMLException: Class not found: Long

 

I am loading it like this

 

long         intervalForFinish    = (Long)   logInfo.get("finishFileAllMinutes");

 

 and even though I know a method of loading it differently, I'd like to know

 

how I can write it in yaml so I really get a Long and not an Int

 

 

thanks a lot in advance and many regards

 

Malte

 

 

Andrey

unread,
Oct 31, 2011, 10:31:21 AM10/31/11
to snakeya...@googlegroups.com
Try this:
!!java.lang.Long

You have to use either the fully qualified name (for the global tag) or specify the value for the local tag.

You can also provide your own implementation for ConstructYamlInt

-
Andrey

Takidoso

unread,
Nov 1, 2011, 4:57:03 AM11/1/11
to SnakeYAML
Hi Andrey
Yes and thanks .. yesterday later on I also came to the solution using
the full qualification.
Does SnakeYaml produce always integers or does it automaticly use long
values as soon the the range for integers is getting small for the
detected value?

If using custom implementation for "ConstructYamlInt" is it to
register somehow, so that there is no need of overwriting nor reading
the code of SnakeYaml?
If so, is there a how to?

Best regards

Andrey

unread,
Nov 1, 2011, 5:35:08 AM11/1/11
to snakeya...@googlegroups.com
Hello,

This is an example how to use your custom way:

I have also added a howto page. Your feedback is welcome.
-
Andrey
Reply all
Reply to author
Forward
0 new messages