{"id":31105951,"url":"https://github.com/bright/sealedified","last_synced_at":"2025-10-09T12:12:15.463Z","repository":{"id":77452379,"uuid":"322975558","full_name":"bright/sealedified","owner":"bright","description":null,"archived":false,"fork":false,"pushed_at":"2021-12-24T17:26:26.000Z","size":86,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-09-17T04:49:24.573Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bright.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2020-12-20T02:07:09.000Z","updated_at":"2021-12-24T17:26:28.000Z","dependencies_parsed_at":null,"dependency_job_id":"8afea4c1-d2c6-4af6-aa4f-82d9aae6ee80","html_url":"https://github.com/bright/sealedified","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/bright/sealedified","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bright%2Fsealedified","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bright%2Fsealedified/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bright%2Fsealedified/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bright%2Fsealedified/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bright","download_url":"https://codeload.github.com/bright/sealedified/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bright%2Fsealedified/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279001438,"owners_count":26083078,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-09T02:00:07.460Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-09-17T04:48:35.497Z","updated_at":"2025-10-09T12:12:15.458Z","avatar_url":"https://github.com/bright.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![](https://jitpack.io/v/bright/sealedified.svg)](https://jitpack.io/#bright/sealedified)\n\n# sealedified #\n\nForward compatible sealed class polymorphic serialization with\n[kotlinx.serialization](https://github.com/Kotlin/kotlinx.serialization/).\n\nIt allows you to properly deserialize an unknown type of object without\ndeserialization errors e.g. to cache the raw data and use it later,\npossibly after updating your application in a way that adds the missing\ntype support.\n\nThis project is very similar to\n[codified enums](https://github.com/bright/codified) that adds forward\ncompatible enums serialization which is also explained\n[here](https://brightinventions.pl/blog/forward-compatible-enums-in-kotlin).\n\n## Installation ##\n\nFirst, add JitPack to your repositories block in Gradle build script.\n\n```kotlin\nrepositories {\n    maven(\"https://jitpack.io\")\n}\n```\n\nThen, add the following dependencies:\n\n```kotlin\nimplementation(\"com.github.bright.sealedified:sealedified:1.6.10\")\nimplementation(\"com.github.bright.sealedified:sealedified-json:1.6.10\")\n```\n\n### Exemplary usage with JSON serialization ###\n\nNormally, when you have a sealed class like this:\n\n```kotlin\n@Serializable\nsealed class Fruit {\n\n    @Serializable\n    data class Apple(val size: Int) : Fruit()\n\n    @Serializable\n    data class Orange(val owner: String?) : Fruit()\n}\n```\n\nand you try to deserialize some type that is not a part of your sealed\nclass hierarchy (yet!), such as `Banana`:\n\n```json\n{\n    \"type\": \"banana\",\n    \"length\": 10.0\n}\n```\n\nusing the default polymorphic serializer generated for your sealed class\n`Fruit`:\n\n```kotlin\nval unknownBananaSerialized =\n    \"\"\"\n        {\n            \"type\": \"banana\",\n            \"length\": 10.0\n        }\n    \"\"\".trimIndent()\nJson.decodeFromString(Fruit.serializer(), unknownBananaSerialized)\n```\n\nyou will get an error such as `SerializationException` because `\"type\":\n\"banana\"` doesn't have a corresponding type in your sealed class\nhierarchy.\n\n`Sealedified` is a sealed class that represents either \"known\" or\n\"unknown\" type. It can either wrap some data type your application\nrecognizes or something that is unknown yet and can be supported in the\nfuture when you extend your implementation.\n\nFor each type you want to wrap with `Sealedified` you must first create\na custom serializer this way:\n\n```kotlin\nobject SealedifiedFruitSerializer : KSerializer\u003cSealedified\u003cFruit, JsonObject\u003e\u003e\n    by SealedifiedJsonSerializer(Fruit.serializer())\n```\n\nand use it instead of the default generated serializer, e.g.\n\n```kotlin\nJson.decodeFromString(SealedifiedFruitSerializer, unknownBananaSerialized)\n```\n\nor, if your object is nested in another serializable class, you can use\n`@Serializable` annotation like this:\n\n```kotlin\n@Serializable\ndata class FruitWrapper(\n    @Serializable(with = SealedifiedFruitSerializer::class)\n    val fruit: Sealedified\u003cFruit, JsonObject\u003e?\n)\n```\n\nHowever, if you have a collection such as `List`, remember to apply the\nannotation to `Sealedified` type - inside the collection:\n\n```kotlin\n@Serializable\ndata class FruitBasket(\n    val fruits: List\u003c@Serializable(with = Fruit.SealedifiedSerializer::class) Sealedified\u003cFruit, JsonObject\u003e\u003e\n)\n```\n\nThanks to that, you will be able to handle the unknown types using\n`when` expressions like this:\n\n```kotlin\nval sealedifiedFruit: Sealedified\u003cFruit, JsonObject\u003e = Json.decodeFromString(SealedifiedFruitSerializer, someFruitSerialized)\n\nwhen (sealedifiedFruit) {\n    is Sealedified.Known -\u003e when (val knownValue = sealedifiedFruit.value) {\n        is Fruit.Apple -\u003e println(\"Size: ${knownValue.size}\")\n        is Fruit.Orange -\u003e println(\"Owner: ${knownValue.owner}\")\n    }\n    is Sealedified.Unknown -\u003e println(\"Raw JSON: ${sealedifiedFruit.raw}\")\n}\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbright%2Fsealedified","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbright%2Fsealedified","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbright%2Fsealedified/lists"}