You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I mentioned this in issue #58 But I think it is it's own issue altogether after doing some digging.
Here's an example of a data class that I serialize which has an optional serializable parameter:
@Serializable
data class Result( @Optional @SerialName("status_id") var statusId: Int? = null)
Currently with how the Kotlinx serialization library is written we write to our JSON map the value of null as a Kotlin String "null".
So for the example above the resulting JSON.stringify() return value would look as follows:
{
"status_id":"null"
}
Cool so this will mean I'm not going to change this value when I POST this payload right? NOPE
"null" is not a valid JSON null value for the API I'm sending POST requests to. Now I'll admit I don't have much experience with API's (I'm learning 🤓). But for my use case in particular this a huge issue. Now for what I think could be the solution.
@Serializable
data class Clz(@Optional @SerialName("status_id") var statusId: Int? = null)
@Test
fun foo() {
val r = Clz()
println(Json.plain.stringify(Clz.serializer(), r))
}
Will print {"status_id":null} in current dev branch.
Could you please provide a self-contained example?
I mentioned this in issue #58 But I think it is it's own issue altogether after doing some digging.
Here's an example of a data class that I serialize which has an optional serializable parameter:
Currently with how the Kotlinx serialization library is written we write to our JSON map the value of
null
as a Kotlin String"null"
.So for the example above the resulting JSON.stringify() return value would look as follows:
Cool so this will mean I'm not going to change this value when I POST this payload right? NOPE
"null"
is not a valid JSON null value for the API I'm sending POST requests to. Now I'll admit I don't have much experience with API's (I'm learning 🤓). But for my use case in particular this a huge issue. Now for what I think could be the solution.In the following file:
https://github.com/Kotlin/kotlinx.serialization/blob/master/runtime/common/src/main/kotlin/kotlinx/serialization/json/JsonParser.kt#L23
Change this line:
internal const val NULL = "null"
to
internal const val NULL = null
The text was updated successfully, but these errors were encountered: