james04
james04

Reputation: 1920

Gson ignore field on serialization under condition

I have an object

data class FileInformation(
    @SerializedName("filename")
    val fileName: String,
    @SerializedName("filesize")
    val fileSize: Long,
    @SerializedName("filedate")
    val fileDate: String,

    var status: Int = FILE_PENDING)

There are times that i want to serialize the above class WITH the status field but other times WITHOUT the status field. How can i do that??

Upvotes: 1

Views: 1931

Answers (1)

You might be looking for Exclusion Strategies - Look at the following link to the GSON documentation for further details: https://howtodoinjava.com/gson/gson-exclude-or-ignore-fields/ :)

Upvotes: 1

Related Questions