JsonParseException when YAML mapping key is a sequence
Description
I am trying to parse a YAML document using Jackson’s YAMLMapper (jackson-dataformat-yaml) in Kotlin/Java, but parsing fails when a mapping key is a sequence. The exception occurs before any schema validation, indicating that YamlMapper cannot handle this case.
YAML Example
? [user, 123]
: name: Иван
age: 30
Kotlin Example
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper
fun main() {
val yaml = """
? [user, 123]
: name: Иван
age: 30
""".trimIndent()
val mapper = YAMLMapper()
val node = mapper.readTree(yaml) // Exception occurs here
}
Exception
com.fasterxml.jackson.core.JsonParseException:
Expected a field name (Scalar value in YAML), got this instead:
<org.yaml.snakeyaml.events.SequenceStartEvent(anchor=null, tag=null, implicit=true)>
Environment
- jackson-dataformat-yaml version: 2.15.x
- Kotlin/Java 17
- OS: macOS / Linux
Notes / Expected Behavior
- According to the YAML spec, using a sequence as a mapping key is valid.
- Jackson fails because
JsonNode only supports scalar keys.
- Ideally, Jackson should either parse the key into a string representation or provide a clear API to handle non-scalar mapping keys.
References
Request
- Support for sequence (and possibly other complex structures) as mapping keys, or
- Better documentation / error message when sequence is used as a key.
JsonParseException when YAML mapping key is a sequence
Description
I am trying to parse a YAML document using Jackson’s
YAMLMapper(jackson-dataformat-yaml) in Kotlin/Java, but parsing fails when a mapping key is a sequence. The exception occurs before any schema validation, indicating thatYamlMappercannot handle this case.YAML Example
Kotlin Example
Exception
Environment
Notes / Expected Behavior
JsonNodeonly supports scalar keys.References
Request