Kaml lacks support for YAML Complex Keys (mapping keys using sequences/mappings) · Issue #700 · charleskorn/kaml · GitHub
More Web Proxy on the site http://driver.im/
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
According to the YAML 1.2 specification §2.2 (see Example 2.11. Mapping between Sequences), YAML allows using sequences or mappings as valid mapping keys (hereafter referred to as "Complex Keys"). These keys are marked with a ? indicator and span until the next : delimiter.
However, Kaml's current architecture doesn't support this specification. Specifically:
The YamlMap.entries currently restricts keys to YamlScalar type, which prevents proper handling of complex keys using nested structures.
Observed Behavior:
Attempt to deserialize a YAML mapping with complex keys, e.g.:
? [key1, key2]: value
Kaml throws:
Property name must not be a list, map, null or tagged value.
(To use 'null' as a property name, enclose it in quotes.)
Reproduction repo
No response
Steps to reproduce
funexample2_11() {
val input ="""? [ New York Yankees, Atlanta Braves ]: [ 2001-07-02, 2001-08-12, 2001-08-14 ]""".trimIndent()
val result =Yaml.default.decodeFromString(
MapSerializer(
(ListSerializer(String.serializer())),
(ListSerializer(String.serializer()))
), input
)
println(result)
}
Expected behaviour
The parser should output a structure equivalent to:
mapOf(
listOf("New York Yankees", "Atlanta Braves") to
listOf("2001-07-02", "2001-08-12", "2001-08-14")
)
In my code, it should print
{[New York Yankees, Atlanta Braves]=[2001-07-02, 2001-08-12, 2001-08-14]}
Actual behaviour
Exception in thread "main" MalformedYamlException at <root> on line 1, column 3: Property name must not be a list, map, null or tagged value. (To use 'null' as a property name, enclose it in quotes.)
at com.charleskorn.kaml.YamlNodeReader.nonScalarMapKeyException(YamlNodeReader.kt:155)
at com.charleskorn.kaml.YamlNodeReader.readMapKey(YamlNodeReader.kt:151)
at com.charleskorn.kaml.YamlNodeReader.readMapping(YamlNodeReader.kt:116)
at com.charleskorn.kaml.YamlNodeReader.readFromEvent(YamlNodeReader.kt:66)
at com.charleskorn.kaml.YamlNodeReader.readNodeAndAnchor(YamlNodeReader.kt:43)
at com.charleskorn.kaml.YamlNodeReader.readNode(YamlNodeReader.kt:39)
at com.charleskorn.kaml.YamlNodeReader.read(YamlNodeReader.kt:37)
at com.charleskorn.kaml.Yaml.parseToYamlNode$kaml(Yaml.kt:85)
at com.charleskorn.kaml.Yaml.decodeFromSource(Yaml.kt:69)
at com.charleskorn.kaml.Yaml.decodeFromString(Yaml.kt:59)
Version information
0.77.0
Any other information
No response
The text was updated successfully, but these errors were encountered:
Describe the bug
According to the YAML 1.2 specification §2.2 (see Example 2.11. Mapping between Sequences), YAML allows using sequences or mappings as valid mapping keys (hereafter referred to as "Complex Keys"). These keys are marked with a
?
indicator and span until the next:
delimiter.However, Kaml's current architecture doesn't support this specification. Specifically:
The
YamlMap.entries
currently restricts keys toYamlScalar
type, which prevents proper handling of complex keys using nested structures.Observed Behavior:
Reproduction repo
No response
Steps to reproduce
Expected behaviour
The parser should output a structure equivalent to:
In my code, it should print
Actual behaviour
Version information
Any other information
No response
The text was updated successfully, but these errors were encountered: