FasterXML / FasterXML/jackson-dataformats-text
JsonParseException when YAML mapping key is a sequence
- Dominant language
- Java
- Stars
- 455
- Forks
- 164
- Avg merge
- 6d 10h
- Merged PRs (30d)
- 2
Description
# 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
```yaml
? [user, 123]
: name: Иван
age: 30
```
## Kotlin Example
```kotlin
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:
```
## 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
* YAML spec: [https://yaml.org/spec/1.2/spec.html#id2760799](https://yaml.org/spec/1.2/spec.html#id2760799)
* Jackson YAMLMapper / YAMLFactory
## Request
* Support for sequence (and possibly other complex structures) as mapping keys, or
* Better documentation / error message when sequence is used as a key.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.