kotlinx-serialization

Serialize Kotlin data classes to JSON, ProtoBuf, and CBOR formats.

Updated Apr 8, 2026
One-click install
npx skills add https://github.com/ClankerGuru/opsx --skill kotlinx-serialization-clankerguru
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: kotlinx-serialization
Source: https://github.com/ClankerGuru/opsx/tree/main/cli/src/main/resources/content/skills/kotlinx-serialization
Command: npx skills add https://github.com/ClankerGuru/opsx --skill kotlinx-serialization-clankerguru

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Kotlin data structures across apps often require conversion to and from JSON, protobuf, and other formats, and a type-safe, boilerplate-free approach makes this repeatable and safe. The kotlinx.serialization library provides a Kotlin-first, reflection-free solution with compile-time generated serializers, enabling consistent and efficient data exchange across platforms.

Core Features & Use Cases

  • Kotlinx.serialization is a Kotlin-first serialization framework that avoids reflection, uses @Serializable annotations, and supports multiple formats (JSON, ProtoBuf, CBOR, HOCON, Properties).
  • It integrates with Gradle and Kotlin tools to generate serializers at compile time, enabling robust data models for HTTP APIs, storage, and IPC.
  • Use cases include streaming data, polymorphic hierarchies, custom serializers, and easy integration with Ktor as a serialization backend.

Quick Start

Configure Gradle with the Kotlinx Serialization plugin, add the required format dependencies, annotate data classes with @Serializable, and start encoding/decoding with Json.

Frequently Asked Questions about kotlinx-serialization

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I serialize Kotlin data classes to JSON without reflection?

Kotlin serialization handles JSON encoding and decoding without reflection by applying the @Serializable annotation to data classes. The KotlinX serialization plugin generates serializers at compile time, ensuring type-safe and boilerplate-free data exchange across platforms.

What is the best way to configure Gradle for kotlinx-serialization across multiple formats?

To configure kotlinx-serialization in Gradle, apply the KotlinX serialization plugin and add the required format dependencies. This setup enables compile-time serializer generation for JSON, ProtoBuf, CBOR, and other formats, supporting robust data models for HTTP APIs and storage.

Does kotlinx-serialization support polymorphic class hierarchies and custom serializers?

Yes, kotlinx-serialization supports polymorphic hierarchies and custom serializers. It provides a Kotlin-first framework to define custom serialization logic and handle streaming data, enabling consistent encoding and decoding across complex data structures in IPC workflows.

Can I use kotlinx-serialization with Ktor for HTTP API data exchange?

Yes, you can use kotlinx-serialization with Ktor as a serialization backend. Annotating data classes with @Serializable and configuring a Json instance enables type-safe HTTP request and response processing, streamlining data exchange in Kotlin applications.

What formats does kotlinx-serialization support for IPC and storage workflows?

Kotlinx-serialization supports multiple formats including JSON, ProtoBuf, CBOR, HOCON, and Properties. These formats facilitate efficient data exchange and storage in Kotlin projects, utilizing compile-time generated serializers to avoid runtime reflection overhead.