Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JsonConfiguration#ignoreUnknownKeys is not working. #1713

Closed
DSeeLP opened this issue Oct 3, 2021 · 1 comment
Closed

JsonConfiguration#ignoreUnknownKeys is not working. #1713

DSeeLP opened this issue Oct 3, 2021 · 1 comment
Assignees

Comments

@DSeeLP
Copy link

DSeeLP commented Oct 3, 2021

Describe the bug
Decoder#decodeSerializableValue ignores JsonConfiguration#ignoreUnknownKeys and an JsonDecodingException is thrown.

To Reproduce
https://gist.github.com/DSeeLP/c5055f616ad0b7e4337cdadd24d1c4e5

Expected behavior
It should deserialize it to FineRestResponse(value=kotlin.Unit) and discard the unknown keys.

Environment

  • Kotlin version: 1.5.31
  • Library version: 1.3.0
  • Kotlin platforms: JVM
  • Gradle version: 7.1.1
  • JRE Version: OpenJDK 11.0.11
  • OS: Fedora 34
@josepanguera
Copy link

josepanguera commented Oct 9, 2021

In your example you're using Unit which is not serializable.

If you add this class

@Serializable
class Discard  // this could be named however you want

and then change the line

println(json.decodeFromString<RestResult<Unit>>(inputText))

for

println(json.decodeFromString<RestResult<Discard>>(inputText))

you'll see that it works as intended and and is in fact respecting the ignoreUnknownKeys setting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants