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

Unboxing null string values from JSON. #1838

Open
mandrachek opened this issue Jan 23, 2022 · 0 comments
Open

Unboxing null string values from JSON. #1838

mandrachek opened this issue Jan 23, 2022 · 0 comments
Labels

Comments

@mandrachek
Copy link

I have an API that I'm dealing with that will return nulls encoded as a string "null", for example:

data model:

@Serializable
data class NullableString(val value: String? = null)

or

@Serializable
data class NullableOtherClass(val value: OtherSerializableObject? = null)

and in either case, the API may return

{ "value": "null" }
  1. Is there a way to provide a custom nullable serializer that will allow me to handle these myself? Just for strings, or for all object types?
  2. If so, is there a way to register this serializer to work with all Any? fields, rather than having to apply an annotation for every field?

If there is a solution for both 1&2, I'm good, however, if there is not, then I've got a problem (several thousand fields and growing in the data model for the API I'm dealing with).

I understand that this used to throw an error in lenient mode (#1600), and that making this the default behavior wouldn't be ideal for all use cases (e.g., German), but I would like to see a setting that perhaps works in conjunction with lenient mode, something like:

Json{ isLenient=true; unboxNullStrings = true }

Turning on that setting, if lenient mode is enabled, should allow:

  • null
  • "null"
  • 'null'

to all be treated as NULL for any nullable field during deserialization.

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

No branches or pull requests

1 participant