-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathIdentityAndTraits.kt
More file actions
27 lines (22 loc) · 985 Bytes
/
IdentityAndTraits.kt
File metadata and controls
27 lines (22 loc) · 985 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package com.flagsmith.entities
import com.google.gson.*
import com.google.gson.annotations.SerializedName
import java.lang.reflect.Type
data class IdentityAndTraits(
@SerializedName(value = "identifier") val identifier: String,
@SerializedName(value = "traits") val traits: List<Trait>,
@SerializedName(value = "transient") val transient: Boolean? = null
)
class IdentityAndTraitsSerializer : JsonSerializer<IdentityAndTraits> {
override fun serialize(src: IdentityAndTraits, typeOfSrc: Type, context: JsonSerializationContext): JsonElement {
// Create a JsonObject with all fields except transient
val jsonObject = JsonObject()
jsonObject.addProperty("identifier", src.identifier)
jsonObject.add("traits", context.serialize(src.traits))
// Only add transient if it's true
if (src.transient == true) {
jsonObject.addProperty("transient", true)
}
return jsonObject
}
}