-
Notifications
You must be signed in to change notification settings - Fork 628
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
Primitive values cannot be serialized to JsonElement #451
Comments
Kotlin: 1.3.31 I'm having similar issue. for NullableSerializer:@Serializable
data class UserProfile(val id:String)
fun test() {
val jsonElement = Json.nonstrict.toJson<UserProfile?>(NullableSerializer(UserProfile.serializer()), null)
println("jsonElement: $jsonElement")
}
for EnumSerializerenum class CollaboratorAffiliation {
OUTSIDE, DIRECT, ALL
}
fun test() {
val el = Json.nonstrict.toJson(EnumSerializer(CollaboratorAffiliation::class), CollaboratorAffiliation.ALL)
println("el: $el")
}
|
Ok, so this seems to apply to all cases where the value is not serialized to a json object (or array, probably), including null. |
sandwwraith
added a commit
that referenced
this issue
May 21, 2019
…when saving/restoring JSON AST Fixes #451
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
While
Json.plain.stringify
can be used on primitives and complex objects alike,Json.plain.toJson
fails on primitive objects with an exception:To Reproduce
Run (e.g.
./gradlew run
) the attached demo project fromprimitive-serialization.zip
Expected behavior
I would expect both Strings and Booleans to be serialized to JsonPrimitive instances.
Environment
The text was updated successfully, but these errors were encountered: