I have such class:
class OutAnswerModel(@field:SerializedName("question")
private val question: Int, @field:SerializedName("answer")
private val answer: Int)
In some situations I will send pattern which will be similar to my constructor above. But in some cases I will need to send answer like JsonArray. I heard smth about classes with two and more constructors here and Kotlin language supports such feature. Unfortunately I didn't understood how to add such functionality to my class. I tried to add constructor like that:
constructor(question: Int,answer: JsonArray) : this()
But here I have to insert to this()
data which as I understood will be used at default constructor of this class. As I see I also have to remove @SerializedName()
from second constructor, but I'm using this class at Retrofit for sending some data to server, and how it will work without fields? What I did incorrectly and how I can solve this task? On the other hand for me it will be better to create two different classes with certain classes but I think it will be to complex and not useful.