Skip to content

Instantly share code, notes, and snippets.

@navczydev
Created October 13, 2021 01:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save navczydev/b5156c204c82d5a8f2a0ec8be15025a1 to your computer and use it in GitHub Desktop.
Save navczydev/b5156c204c82d5a8f2a0ec8be15025a1 to your computer and use it in GitHub Desktop.
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