config
config copied to clipboard
double value (e.g., 1.0) is translated to ConfigInt(1) instead of ConfigDouble(1.0)
val config = ConfigFactory.parseString(
"""
|decoders = [
| { a : 1.0 },
| { b : 2.2 },
| { c : 3.3 }
|]
""".stripMargin)
val decoders = config.getObjectList("decoders")
decoders.foreach(co => println(co.toConfig.entrySet()))
prints
[a=ConfigInt(1)] [b=ConfigDouble(2.2)] [c=ConfigDouble(3.3)]`
I'm expecting [a=ConfigDouble(1.0)].
Thanks, Kyunam
In ConfigNumber.newNumber it chooses an integer representation if it would be lossless.
In general if you depend on the parsed type (vs the gettable type with getDoubleList) some uses of the library will break, such as the ability to override values with env vars and properties. So if possible avoid relying on this.
I’m not sure of the implications of changing how it works now, it’s possible we could.
Thank you Havoc. It would be awesome if it could be changed, then I’d feel very com.typesafed :)
Thanks again.
I also met this problem and it made me confused a lot. The situation is when to parse configurations dynamically from a file, I know neither the key names nor the value types ,both can change dynamically, so I can't use the the methods like getInt or getDouble and during runtime, this problem caused 'java int cannot be converted to double' error. I don't know whether other literals will be parsed like that, which makes me quite unconfident with the com.typesafe.config.
Same issue for dynamically loaded config. #581 (originalText) could help if it's quicker