Hello guys. I am using kotlinx.serialization in my...
# server
n
Hello guys. I am using kotlinx.serialization in my ktor api and have a data class as below.
Copy code
@Serializable
data class User(
  var email: String = "", 
  @JsonIgnore var password: String = ""
)
Which annotation can i use on the password field to ignore it "only" in the http response but not within the application. For example Ignore it when:
Copy code
get {
    call.respond(User("email", "some password"))
}
Don't ignore it when:
Copy code
fun checkUserPassword(email: String) {
    val user = getUserPasswordFromDatabaseByEmail<User>(email)
    // The print below does not work (I want it to work since it is not yet part of the response)
    println(user.password)
}
m
And using 2 different classes? One with pass and another without it?
👍 2
✔️ 1
n
That is what i had thought of. I didn't want to create another class but i guess it is the only option now.
👌 1
m
This is the simplest idea that comes to mind:
Copy code
get {
    call.respond(User("email", "some password").copy(password = ""))
}
you could even encapsulate the copying with empty values in an instance method or extension function declared in the router file/module.