Issue
I want to send to the API only the data that I indicate in my data class.
data class UserRequestDTO(
val name: String = "",
val surname: String = ""
)
My empty class
val userDTO = UserRequestDTO()
MyService.getService().users()
My request
@POST("/vo/search")
fun users(
@Body userRequestDTO: UserRequestDTO
): Call<ResponseDTO>
But the following json is being sent:
{"name": "", "surname": ""}
How can I have a class in which I only send the data that I fill in? don't want any data to be sent, and if for example I fill in the name, I don't want the last name to be sent
Solution
Making them optional should result in not sending them:
data class UserRequestDTO(
val name: String? = null,
val surname: String? = null
)
Answered By - Stephan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.