{"id":18549311,"url":"https://github.com/petertrr/merge-data-class","last_synced_at":"2025-05-15T09:12:02.846Z","repository":{"id":39882618,"uuid":"458806767","full_name":"petertrr/merge-data-class","owner":"petertrr","description":"Kotlin Symbol Processor to construct data classes from incomplete sources while preserving nullability cheks","archived":false,"fork":false,"pushed_at":"2023-02-15T19:51:47.000Z","size":125,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-26T07:28:55.974Z","etag":null,"topics":["data-class","kotlin","ksp","type-safety"],"latest_commit_sha":null,"homepage":"","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/petertrr.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":"2022-02-13T12:46:23.000Z","updated_at":"2022-06-19T20:13:00.000Z","dependencies_parsed_at":"2024-11-06T20:53:43.177Z","dependency_job_id":null,"html_url":"https://github.com/petertrr/merge-data-class","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/petertrr%2Fmerge-data-class","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/petertrr%2Fmerge-data-class/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/petertrr%2Fmerge-data-class/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/petertrr%2Fmerge-data-class/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/petertrr","download_url":"https://codeload.github.com/petertrr/merge-data-class/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239269808,"owners_count":19610870,"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","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":["data-class","kotlin","ksp","type-safety"],"created_at":"2024-11-06T20:38:38.066Z","updated_at":"2025-02-17T10:14:51.484Z","avatar_url":"https://github.com/petertrr.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# merge-data-class KSP processor\nThis is a Kotlin Symbol Processor implementation that is intended to ease some tasks related to data classes by generating\nboilerplate code that helps to preserve type-safe nullability when working with incomplete data sources.\n\nSometimes there are cases when data comes from different sources, e.g. some fields are read from configuration file\nand others are set by user on the command line. After application startup those two sets of values sum up into a data class\nwhere all fields have to be present, i.e. they are non-nullable in terms of Kotlin type system. So, to construct such a class\none might want to read all values manually, or create a special logic for iterating over class properties etc.\nThis approach however leads to a lot of boilerplate.\n\nOr there might be another approach - to make properties nullable, construct data class instances from all data sources \nand then merge them. However, this passes nullable properties down the whole application and introduces a huge number of\nunnecessary `!!` all over the code base.\n\n`merge-data-class` serves as a pretty simple code generation solution for this case. Based on a data class it would generate\na class with nullable properties and a merge method, which would return an instance of the original class while also performing\nnullability checks.\n\nConsider the code below:\n```kotlin\n@BuildFromPartial\ndata class Foo(\n    val field1: Type1,\n    val field2: Type2?,\n)\n```\n\n`merge-data-class` will generate the following code:\n\n```kotlin\ndata class FooPartial(\n    val field1: Type1?,\n    val field2: Type2?,\n) {\n    fun merge(other: FooPartial): Foo {\n        return Foo(\n            field1 ?: other.field1,\n            field2 ?: other.field2\n        )\n    }\n}\n```\n\n# Using it in a gradle project\nThis plugin can be used as any other KSP processor: apply the KSP plugin and add required dependencies:\n```kotlin\nplugins{\n    kotlin(\"ksp\") version \"1.6.21\"\n}\n\n## Using it in a KMP project\nAs described in [Kotlin docs](https://kotlinlang.org/docs/ksp-multiplatform.html), there are some differences\nin using KSP in Multiplatform proejct over a single-platform project.\nkotlin\nplugins{\n    id(\"com.google.devtools.ksp\") version \u003cksp version\u003e\n}\n\nkotlin {\n    sourceSets {\n        commonMain {\n          implementation(\"io.github.petertrr.ksp:merge-data-class-annotations:0.1.0\")\n        }\n    }\n}\n\ndependencies {\n    \"ksp\"(\"io.github.petertrr.ksp:merge-data-class-annotations:0.1.0\")\n    \"kspCommonMainMetadata\"(\"io.github.petertrr.ksp:merge-data-class-ksp:0.1.0\")\n}\n  \ndependencies {\n    compileOnly(\"io.github.petertrr:merge-data-class-annotations:0.1.0\")\n    ksp(\"io.github.petertrr:merge-data-class-ksp:0.1.0\")\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpetertrr%2Fmerge-data-class","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpetertrr%2Fmerge-data-class","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpetertrr%2Fmerge-data-class/lists"}