JsonNames

annotation class JsonNames(val names: String)

Indicates that the field can be represented in JSON with multiple possible alternative names. Json format recognizes this annotation and is able to decode the data using any of the alternative names.

Unlike SerialName annotation, does not affect JSON encoding in any way.

Example of usage:

@Serializable
data class Project(@JsonNames("title") val name: String)

val project = Json.decodeFromString<Project>("""{"name":"kotlinx.serialization"}""")
println(project)
val oldProject = Json.decodeFromString<Project>("""{"title":"kotlinx.coroutines"}""")
println(oldProject)

This annotation has lesser priority than SerialName.

See also

Constructors

Link copied to clipboard
fun JsonNames(vararg names: String)

Properties

Link copied to clipboard
val names: Array<out String>