Agent skill
kotlin-serialization
kotlinx.serialization - JSON, Protobuf, custom serializers
Install this agent skill to your Project
npx add-skill https://github.com/pluginagentmarketplace/custom-plugin-kotlin/tree/main/skills/kotlin-serialization
SKILL.md
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
| Issue | Resolution |
|---|---|
| "Serializer not found" | Add @Serializable or plugin |
| Unknown property fails | Set ignoreUnknownKeys = true |
Usage
Skill("kotlin-serialization")
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
kotlin-testing
Kotlin testing - JUnit 5, MockK, Kotest, coroutine testing
kotlin-spring
Spring Boot with Kotlin - controllers, services, coroutines
kotlin-di
Dependency Injection - Hilt, Koin, scopes, testing
kotlin-fundamentals
Kotlin language fundamentals - syntax, null safety, data classes, extensions
kotlin-android
Modern Android development - Jetpack, Compose, Architecture Components
kotlin-multiplatform
Kotlin Multiplatform - shared code, expect/actual, iOS integration
Didn't find tool you were looking for?