make sure you also set `encodeDefaults = false` in...
# serialization
n
make sure you also set
encodeDefaults = false
in
Json
constructor call
g
I’ve added it like that and I still receive the error:
Copy code
HttpClient(Js) {
        install(JsonFeature) {
            serializer = KotlinxSerializer(Json(encodeDefaults = false))
        }
Seems ok right?
This is my model:
Copy code
@Serializable
data class Profile(
    val id: Int,
    val firstName: String? = null,
    val lastName: String? = null) {

    constructor(user: User): this(user.id, user.firstName, user.lastName)
}
So @Optional on those fields with default value works, not encodeDefaults = false for some reason
n
but you need to add
@Optional
to each value with default values, i wonder if it is because you add a constructor
Copy code
@Serializable
data class Profile(
    val id: Int,
    @Optional val firstName: String? = null,
    @Optional val lastName: String? = null) {
}
this should certainly work.. maybe try turning your contructor into a companion object method like
operator fun invoke(user: User)