0

I have the below data class

data class ApiPost(
@SerializedName("LoginId")  var userName: String,
@SerializedName("Password") var password: String,
@SerializedName("NewPassword") var newPassword: String,
@SerializedName("FileType") var FileType: String,
@SerializedName("UserId") var UserId: String,
@SerializedName("CountryId") var CountryId: String,
@SerializedName("DateOfBirth") var DateOfBirth: String,
@SerializedName("Mobile") var Mobile: String,
@SerializedName("CountryName") var CountryName: String,
@SerializedName("CompanyName") var CompanyName: String,
@SerializedName("IsAnonymous") var IsAnonymous: String,
@SerializedName("EmployeeIssue") var EmployeeIssue: String,
@SerializedName("DetailedInformation") var DetailedInformation: String,
@SerializedName("EmployeeId") var EmployeeId: String,
@SerializedName("EmployeeEmailId") var EmployeeEmailId: String,
@SerializedName("FCMId") var FCMId: String
)

To initialise the object I will have to pass all the values.

But my question is what if I only want to pass 2 values to object. How can that be done?

val apiPost: ApiPost=ApiPost()
                    apiPost!!.userName = "[email protected]"
                    apiPost!!.password = "12345"

What needs to be done here?

2

1 Answer 1

0

Thanks to the answer over here Kotlin data class optional variable

Initialised default value to the data class

data class ApiPost(
        @SerializedName("LoginId")  var userName: String ="",
        @SerializedName("Password") var password: String ="",
        @SerializedName("NewPassword") var newPassword: String ="",
        @SerializedName("FileType") var FileType: String ="",
        @SerializedName("UserId") var UserId: String ="",
        @SerializedName("CountryId") var CountryId: String ="",
        @SerializedName("DateOfBirth") var DateOfBirth: String ="",
        @SerializedName("Mobile") var Mobile: String ="",
        @SerializedName("CountryName") var CountryName: String ="",
        @SerializedName("CompanyName") var CompanyName: String ="",
        @SerializedName("IsAnonymous") var IsAnonymous: String ="",
        @SerializedName("EmployeeIssue") var EmployeeIssue: String ="",
        @SerializedName("DetailedInformation") var DetailedInformation: String ="",
        @SerializedName("EmployeeId") var EmployeeId: String ="",
        @SerializedName("EmployeeEmailId") var EmployeeEmailId: String ="",
        @SerializedName("FCMId") var FCMId: String =""
    )

And called it as

ApiPost(userName = "[email protected]", password = "12345")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.