Skip to content

Include failed content when decoding #197

@hfhbd

Description

@hfhbd

Like kotlinx.serialization.json, it would be helpful to include the content when decoding, ideally the attribute/element (including its namespace) that failed.

Given class:

@Serializable
data class A(val a: String, val c: Int)

Using json Json.decodeFromString(A.serializer(), """{"a": "b", "d": 42}"""):

kotlinx.serialization.json.internal.JsonDecodingException: Unexpected JSON token at offset 13: Encountered an unknown key 'd' at path: $.a
Use 'ignoreUnknownKeys = true' in 'Json {}' builder to ignore unknown keys.
JSON input: {"a":  "b", "d":  42}

Using xml XML.decodeFromString(A.serializer(), """<A a="asd" d="asfd"/>"""):

nl.adaptivity.xmlutil.serialization.UnknownXmlFieldException: Could not find a field for name (ATest.A) A/d (Attribute)
  candidates: a (Attribute), c (Attribute) at position Line number = 1
Column number = 22
System Id = null
Public Id = null
Location Uri= null
CharacterOffset = 21

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions