Closed fiotti closed 1 day ago
Try using withquotenecessarystrings on your serializerbuilder. That should automatically add quotes around scalars that are numbers only. Along with other special values.
Using WithAttemptingUnquotedStringTypeDeserialization()
during deserialization and WithQuoteNecessaryStrings()
during serialization does indeed solve the issue.
Thanks! I had completely missed it 😅
Is your feature request related to a problem? Please describe. All values are treated as strings, but numeric strings are not escaped, example:
I think this does not directly violate YAML specs, but according to YAML specs, plain (unquoted) scalars may be interpreted in special ways. By serializing in this format we lost the information that the value was originally a string, now it looks more like an integer.
This might not be a big problem for most strings, but YAML specs gives an example of an octal number as a sequence of digits with a leading
0
, as an example, the YAML value014
is interpreted as "14 octal", which is12
.Describe the solution you'd like A more versatile approach would be to add quotes to strings that look like numbers.
Describe alternatives you've considered I considered using a custom
YamlFormatter
, but there is noFormatAsString()
method exposed, so this is not a viable solution.I ended up wrapping in a custom
QuotedString
class all the strings that look like numbers, then using a customIYamlTypeConverter
to emit aScalar
withScalarStyle.SingleQuoted
.Additional context In my specific case I'm passing the output YAML to Helm, which interprets that
01234
value as the integer value668
instead of as the string'01234'
, breaking some functionalities.Thank you!