JsonNames
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)
Content copied to clipboard
This annotation has lesser priority than SerialName.