Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
val formatExplicitExcludeNullsFalse = Json { explicitNulls = false }
val flutterExpert = Expert(id = 1, "Roman", Category.FLUTTER, null)
val jsonFlutterExpert = formatExplicitExcludeNullsFalse.encodeToString(flutterExpert)
println("Encoded FlutterExpert result: $jsonFlutterExpert")
val formatExplicitExcludeNullsTrue = Json { explicitNulls = true }
println("Decoded FlutterExpert: ${formatExplicitExcludeNullsTrue.decodeFromString<Expert>(jsonFlutterExpert)}")
/*
Exception in thread "main" kotlinx.serialization.MissingFieldException:
Field 'publishedArticles' is required for type with serial name 'Expert', but it was missing
at kotlinx.serialization.internal.PluginExceptionsKt.throwMissingFieldException(PluginExceptions.kt:20)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment