dimitriremoiville/cc-mobile/kotlinx-serialization
Claude Code and agent skill by dimitriremoiville/cc-mobile
- community
Checking that the SKILL.md file is still in the repository.
kotlinx.serialization patterns for KMP — JSON configuration, polymorphism with sealed hierarchies, custom serializers, enum handling, null/default discipline, and KMP-specific gotchas. Load whenever writing or reviewing serialized boundaries (Ktor bodies, SQLDelight blob encodings, settings values).
Install
npx vskill@latest install dimitriremoiville/cc-mobile/kotlinx-serializationSKILL.md
The same SKILL.md was published earlier as dimitriremoiville/cc-mobile/kotlinx-serialization.
kotlinx.serialization
Json configuration
One shared Json instance per app, configured once:
ignoreUnknownKeys = true— forward-compat; new server fields don't crash old clients.encodeDefaults = false— smaller payloads; omit fields that equal their default.explicitNulls = false— a missing field deserializes to the default, anullexplicitly clears.isLenient = false— fail fast on malformed JSON, don't guess.coerceInputValues = true— a bad enum in the wire becomes the property default instead of a crash. Accept the trade-off or setfalse.
Inject it into Ktor + anywhere else you parse/emit:
Serializable classes
- Field names in Kotlin stay
camelCase. Use@SerialNameto map tosnake_caseon the wire. - Enum serialization uses the enum constant name by default; override with
@SerialNamefor clarity and forward-compat.
Polymorphism
For API unions, model as a sealed hierarchy:
classDiscriminator = "type" (set on Json) means the wire format is:
Server-flexible discriminator? Use JsonContentPolymorphicSerializer:
Annotate the sealed interface with @Serializable(with = PaymentSerializer::class).
kotlinx-datetime
Don't roll your own timestamp format. kotlinx-datetime serializes Instant as ISO-8601 by default.
For custom formats (legacy server), write a KSerializer<Instant> and annotate the field:
Value classes
Value classes serialize as their underlying type (Long, String, etc.), which usually matches the wire. Use them freely at the DTO layer for IDs:
Gotchas
Default values and polymorphism
A @Serializable sealed interface with concrete types that have default-valued properties will lose those on decode unless every instance carries an explicit discriminator. Keep defaults minimal on polymorphic members.
Enum name mismatch
coerceInputValues = true turns unknown enum values into the property default. This is fine for forward-compat but dangerous if you rely on OrderStatus.PENDING vs a silent fallback. Log the incoming unknown via a custom deserializer if you need visibility.
iOS freeze
No longer a concern with new MM but in legacy memory model: @Serializable objects should be immutable data classes. Don't share mutable serializable types across threads.
Generated serializersModule
For third-party sealed types outside your control, register a SerializersModule:
Testing
Prefer parser round-trips to string assertions, unless the exact byte output is contractual:
Golden assertions have their place for snapshot tests of your API serialization — keep them in one place so a serializer change is a focused review.
Hard nos
- No leaking
@SerializableDTOs into the domain layer. Map. - No
Json { }per call site. One shared instance. - No
isLenient = truein new code. - No
explicitNulls = truewhen you want to omit fields on encode — useencodeDefaults = false+ nullable-with-default instead. - No serializing
Throwableto the wire. Model domain errors as DTOs.
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingkmm/.claude/skills/kotlinx-serialization/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/dimitriremoiville/cc-mobile/kotlinx-serialization)