I am working on an Android app and I am trying to find a way to a data class which contain optional parameters. the data class is a part of Retrofit command so, when the params is not there, I do not want him to be sent.
data class Status(
@field:com.google.gson.annotations.SerializedName("power") val power: Int?,
@field:com.google.gson.annotations.SerializedName("state") val state: Int?
)
So basically, I would expect the outpout to be either:
{
"power": 1
}
or
{
"state": 45
}
or
{
"power": 1,
"state": 45
}
and the data class must be respectively called as:
Status(power=1) or Status(state=45) or Status(power=1, status=45)
Any idea ? I am will have multiple params and I would like to prevent writing a class for every cases
As of now, I have a error when using it as for example I am only doing Status(power=1) so it complains that the params state is missing.
Thanks