kotlin-serialization

kotlinx.serialization - JSON, Protobuf, custom serializers

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "kotlin-serialization" with this command: npx skills add pluginagentmarketplace/custom-plugin-kotlin/pluginagentmarketplace-custom-plugin-kotlin-kotlin-serialization

Kotlin Serialization Skill

Type-safe serialization with kotlinx.serialization.

Topics Covered

JSON Serialization

@Serializable
data class User(
    val id: Long,
    val name: String,
    @SerialName("email_address") val email: String,
    val createdAt: Instant = Instant.now()
)

val json = Json {
    ignoreUnknownKeys = true
    encodeDefaults = true
    prettyPrint = true
}

val user = json.decodeFromString<User>(jsonString)
val output = json.encodeToString(user)

Custom Serializers

object InstantSerializer : KSerializer<Instant> {
    override val descriptor = PrimitiveSerialDescriptor("Instant", PrimitiveKind.LONG)
    override fun serialize(encoder: Encoder, value: Instant) = encoder.encodeLong(value.toEpochMilli())
    override fun deserialize(decoder: Decoder) = Instant.ofEpochMilli(decoder.decodeLong())
}

@Serializable
data class Event(
    @Serializable(with = InstantSerializer::class) val timestamp: Instant
)

Polymorphic Serialization

@Serializable
sealed class Response {
    @Serializable @SerialName("success")
    data class Success(val data: String) : Response()

    @Serializable @SerialName("error")
    data class Error(val message: String) : Response()
}

val json = Json { classDiscriminator = "type" }

Troubleshooting

IssueResolution
"Serializer not found"Add @Serializable or plugin
Unknown property failsSet ignoreUnknownKeys = true

Usage

Skill("kotlin-serialization")

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Automation

kotlin-compose

No summary provided by upstream source.

Repository SourceNeeds Review
Automation

kotlin-android

No summary provided by upstream source.

Repository SourceNeeds Review
Automation

kotlin-testing

No summary provided by upstream source.

Repository SourceNeeds Review