How do I serialize a class with null fields? (I'm ...
# kvision
u
How do I serialize a class with null fields? (I'm trying to pass it to backend using the rest client)
Copy code
Serializer for class 'null' is not found.
r
Should work. Could you post some code sample?
u
Copy code
fun addUser(systemUser: SystemUser): Promise<dynamic> {
    println("Adding: $systemUser")
    return RestClient().requestDynamic("/api/v1/users", systemUser) {
        method = <http://HttpMethod.POST|HttpMethod.POST>
    }
}
Copy code
@Serializable
data class SystemUser (
    var id: Int? = null,
    @Contextual val creationDate: Date? = Date(),
    val username: String,
    val password: String? = null,
    val permissionLevel: String
)
Copy code
Adding: SystemUser(id=null, creationDate=Thu Sep 02 2021 16:36:47 GMT+0200 (Central European Summer Time), username=testadmin, password=test, permissionLevel=ADMIN)
main.bundle.js:2 Uncaught Mf {message: "Serializer for class 'null' is not found.\nMark the…erializable or provide the serializer explicitly.", cause: undefined, name: "Mf", stack: "Mf: Serializer for class 'null' is not found.\nMark… (<http://localhost:8080/main.bundle.js:2:2354664>)"}
u
🤦