Skip to content

JsonParseException when YAML mapping key is a sequence #589

@af851574-oss

Description

@af851574-oss

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    yamlIssue related to YAML format backend

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions