Ktor serialization question

I have a data class that models a response from Firebase on user sign in. It looks like the following:

@Serializable data class SignInResponse( val kind: String? = null, val localId: String? = null, val email: String? = null, val displayName: String? = null, val idToken: String? = null, val registered: Boolean? = null, val error: ErrorResponse? = null } 

On my httpClient I have set it up like so:

val httpClient = HttpClient(CIO) { install(ContentNegotiation) { json(Json { ignoreUnknownKeys = true }) } // other config here... } 

I am using kotlinx.serialization

I have another class FirebaseAuthenticationClient that uses that httpClient to make requests into Firebase.

My question is, is there a way to not have to mark all properties in the SignInResponse class nullable and give a default value of null? I would prefer it if the serializer handled this automatically and if a property on the response wasn’t present, it nulled it by default without me having to explicity mark it as so. As it stands, an exception is thrown every time I remove ?. I thought that was the purpose of ignoreUnknownKeys, but that does not seem to be the case.

Coming from C# this seems very weird to me as this would be handled automatically and here I’m trying to avoid having to mark all properties as nullable across all my response objects.

submitted by /u/genericprogrammer
[link] [comments]