{"id":31105995,"url":"https://github.com/bright/codified","last_synced_at":"2025-09-17T04:52:07.315Z","repository":{"id":46965792,"uuid":"280721255","full_name":"bright/codified","owner":"bright","description":null,"archived":false,"fork":false,"pushed_at":"2024-06-16T19:29:04.000Z","size":103,"stargazers_count":19,"open_issues_count":1,"forks_count":3,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-07T02:38:15.060Z","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}},"created_at":"2020-07-18T19:05:33.000Z","updated_at":"2025-03-30T00:47:05.000Z","dependencies_parsed_at":"2024-06-16T20:29:22.358Z","dependency_job_id":"2fe455ec-08ab-41c3-b9a7-248dc3e1f94c","html_url":"https://github.com/bright/codified","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/bright/codified","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bright%2Fcodified","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bright%2Fcodified/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bright%2Fcodified/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bright%2Fcodified/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bright","download_url":"https://codeload.github.com/bright/codified/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bright%2Fcodified/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275537148,"owners_count":25482345,"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-09-17T02:00:09.119Z","response_time":84,"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:52:02.913Z","updated_at":"2025-09-17T04:52:07.301Z","avatar_url":"https://github.com/bright.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"![build](https://github.com/bright/codified/actions/workflows/build.yml/badge.svg?branch=master)\n\n# codified #\n\nFacilitates objects \"codification\".\n\nAt the moment, the main application of this library is making it easier to encode and decode enum classes in a forward compatible way.\n\n## Installation and usage ##\n\nFirst, make sure Maven Central is in your repositories block in Gradle build script.\n\n```kotlin\nrepositories {\n    mavenCentral()\n}\n```\n\n### CodifiedEnum ###\n\nAdd the following dependency in order to access `CodifiedEnum` class.\n\n```kotlin\nimplementation(\"dev.bright.codified:enums:1.9.24.1\")\n```\n\n`CodifiedEnum` is a sealed class which represents either \"known\" or \"unknown\" enum type depending on the `code`\nit is represented by. For example:\n\n```kotlin\nenum class Fruit(override val code: String) : Codified\u003cString\u003e {\n    APPLE(\"Apple\")\n}\n\nval codifiedAppleFromEnum: CodifiedEnum\u003cFruit, String\u003e = Fruit.APPLE.codifiedEnum()\nval codifiedAppleFromString: CodifiedEnum\u003cFruit, String\u003e = \"Apple\".codifiedEnum()\nval codifiedCherry: CodifiedEnum\u003cFruit, String\u003e = \"Cherry\".codifiedEnum()\n\nAssertions.assertEquals(Fruit.APPLE, codifiedAppleFromEnum.knownOrNull())\nAssertions.assertEquals(Fruit.APPLE, codifiedAppleFromString.knownOrNull())\nAssertions.assertEquals(Fruit.APPLE.code, codifiedAppleFromEnum.code())\nAssertions.assertEquals(Fruit.APPLE.code, codifiedAppleFromString.code())\nAssertions.assertEquals(codifiedAppleFromEnum, codifiedAppleFromString)\nAssertions.assertNotEquals(codifiedAppleFromEnum, codifiedCherry)\nAssertions.assertEquals(\"Cherry\", codifiedCherry.code())\n\nwhen (val orange = \"Orange\".codifiedEnum\u003cFruit\u003e()) {\n    is CodifiedEnum.Known -\u003e when (orange.value) {\n        Fruit.APPLE -\u003e TODO()\n    }\n    is CodifiedEnum.Unknown -\u003e TODO()\n}\n```\n\n### CodifiedEnum serialization ###\n\n#### kotlinx.serialization ####\n\nAdd the following dependency in order to access `CodifiedEnum` serializer using\n[Kotlin serialization](https://github.com/Kotlin/kotlinx.serialization).\n\n```kotlin\nimplementation(\"dev.bright.codified:enums-serializer:1.9.24.1\")\n```\n\nAdd `CodifiedSerializer` object for your enum class to handle both known and unknown enum types.\n\n```kotlin\nenum class Fruit(override val code: String) : Codified\u003cString\u003e {\n    APPLE(\"Apple\");\n\n    object CodifiedSerializer : KSerializer\u003cCodifiedEnum\u003cFruit, String\u003e\u003e by codifiedEnumSerializer()\n}\n\n@Serializable\ndata class FruitWrapper(\n    @Serializable(with = Fruit.CodifiedSerializer::class)\n    val fruit: CodifiedEnum\u003cFruit, String\u003e\n)\n\nval json = Json(JsonConfiguration.Stable)\n\nval wrapperWithApple = FruitWrapper(Fruit.APPLE.codifiedEnum())\nval string = json.stringify(FruitWrapper.serializer(), wrapperWithApple)\nAssertions.assertEquals(\"{\\\"fruit\\\":\\\"Apple\\\"}\", string)\n\nval jsonWithApple = \"{\\\"fruit\\\":\\\"Apple\\\"}\"\nval wrapperFromJsonWithApple = json.parse(FruitWrapper.serializer(), jsonWithApple)\nAssertions.assertEquals(Fruit.APPLE, wrapperFromJsonWithApple.fruit.knownOrNull())\n\nval jsonWithOrange = \"{\\\"fruit\\\":\\\"Orange\\\"}\"\nval wrapperFromJsonWithOrange = json.parse(FruitWrapper.serializer(), jsonWithOrange)\nAssertions.assertEquals(\"Orange\", wrapperFromJsonWithOrange.fruit.code())\n```\n\nWhen `CodifiedEnum` is a parameter of a collection such as `List`,\n`@Serializable` should be applied to `CodifiedEnum` - inside the\ncollection type:\n\n```kotlin\n@Serializable\ndata class FoodBasket(\n    val fruits: List\u003c@Serializable(with = Fruit.CodifiedSerializer::class) CodifiedEnum\u003cFruit, String\u003e\u003e,\n    val vegetables: List\u003c@Serializable(with = Vegetable.CodifiedSerializer::class) CodifiedEnum\u003cVegetable, String\u003e\u003e\n)\n```\n\n#### Gson ####\n\nAdd this dependency:\n\n```kotlin\nimplementation(\"dev.bright.codified:enums-gson:1.9.24.1\")\n```\n\nand register the `TypeAdapterFactory` for `CodifiedEnum`:\n\n```kotlin\nval gson = GsonBuilder()\n    .registerTypeAdapterFactory(CodifiedEnumTypeAdapter.Factory())\n    .create()\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbright%2Fcodified","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbright%2Fcodified","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbright%2Fcodified/lists"}