I have the following data class in Kotlin:
import com.google.gson.annotations.SerializedName
data class RouteGroup(
@SerializedName("name") var name: String,
@SerializedName("id") var id: Int
)
Sometimes I need to create an object with both fields, sometimes with only one of them.
How can I do this?
EDIT
This is not the duplicate of this question: Can Kotlin data class have more than one constructor? That question shows how to set a default value for a field. But in my case, I don't need to serialize the field with the default value. I want a field to be serialized only when I explicitly assign a value to it.