You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If a Yaml value is a String but the actual value appears to be parsable as integer or boolean, scala-yaml automatically translates it into java.lang.Integer and java.lang.Boolean. This changes the yaml schema silently and unexpectedly. With typical kubernetes Yaml where values such as "2" or "true" are of type String , the Yaml cannot be parsed after scala-yaml serializes the data.
Example code:
valyaml1=""" revision: "2" """.as[Any].toOption.get
// We expect `revision` to be of type `String` and value `"2"`, instead have an integer:
assert(yaml1.asInstanceOf[Map[String, Any]].apply("revision").isInstanceOf[java.lang.Integer])
valyaml2=""" enabled: "true" """.as[Any].toOption.get
// We expect `enabled` to be of type `String` and value `"true"`, instead have a Boolean:
assert(yaml2.asInstanceOf[Map[String, Any]].apply("enabled").isInstanceOf[java.lang.Boolean])
I expected it to be a String in each case, since "2" and "true" are just strings.
Not sure if this is a feature that can be turned off, please advise.
The text was updated successfully, but these errors were encountered:
winitzki
changed the title
String types should not be silently converted
String types should not be silently converted to Integer or BooleanApr 25, 2023
…#221)
* issue220 - do not convert quoted strings into other primitive types
* more tests
* formatting
* add more unit tests
* code cleanup
* code cleanup
* more unit tests
* move tests to ScalarSuite
* minimize changes
---------
Co-authored-by: sergei.winitzki <sergei.winitzki@workday.com>
If a Yaml value is a
String
but the actual value appears to be parsable as integer or boolean,scala-yaml
automatically translates it intojava.lang.Integer
andjava.lang.Boolean
. This changes the yaml schema silently and unexpectedly. With typical kubernetes Yaml where values such as"2"
or"true"
are of typeString
, the Yaml cannot be parsed afterscala-yaml
serializes the data.Example code:
I expected it to be a
String
in each case, since"2"
and"true"
are just strings.Not sure if this is a feature that can be turned off, please advise.
The text was updated successfully, but these errors were encountered: