{"id":21206223,"url":"https://github.com/rtmigo/repr_kt","last_synced_at":"2026-05-07T21:38:39.323Z","repository":{"id":61833961,"uuid":"461874368","full_name":"rtmigo/repr_kt","owner":"rtmigo","description":"Kotlin/JVM library converting Kotlin objects to strings that are Kotlin code too","archived":false,"fork":false,"pushed_at":"2022-10-23T07:56:43.000Z","size":170,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-14T23:11:56.212Z","etag":null,"topics":["code-generation","jvm","kotlin","library","python","serialization"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rtmigo.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}},"created_at":"2022-02-21T13:29:46.000Z","updated_at":"2022-02-21T22:41:05.000Z","dependencies_parsed_at":"2023-01-20T08:46:48.382Z","dependency_job_id":null,"html_url":"https://github.com/rtmigo/repr_kt","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/rtmigo/repr_kt","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rtmigo%2Frepr_kt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rtmigo%2Frepr_kt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rtmigo%2Frepr_kt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rtmigo%2Frepr_kt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rtmigo","download_url":"https://codeload.github.com/rtmigo/repr_kt/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rtmigo%2Frepr_kt/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32757494,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-07T02:14:30.463Z","status":"ssl_error","status_checked_at":"2026-05-07T02:14:29.405Z","response_time":62,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["code-generation","jvm","kotlin","library","python","serialization"],"created_at":"2024-11-20T20:54:54.132Z","updated_at":"2026-05-07T21:38:39.288Z","avatar_url":"https://github.com/rtmigo.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Generic badge](https://img.shields.io/badge/JVM-8+-blue.svg)\n[![Maven Central](https://img.shields.io/maven-central/v/io.github.rtmigo/repr.svg)](https://search.maven.org/artifact/io.github.rtmigo/repr)\n\n# [repr](https://github.com/rtmigo/repr_kt#readme)\n\nKotlin/JVM library. Converts Kotlin objects to strings.\n\n`.toRepr()` is like `.toString()`, but aims to produce a valid Kotlin code.\n\nLet's say we have the following:\n\n```kotlin\ndata class Planet(val name: String, \n                  val diameter: Int)\n\nval data = mapOf(\n    \"planets\" to listOf(\n        Planet(\"Venus\", 12104),\n        Planet(\"Earth\", 12742),\n        Planet(\"Mars\", 6779)    \n    ),\n    \"location\" to \"Solar System\"\n)\n```\n\nCalling `data.toString()` would give us this:\n\n```text\n{\n    planets=[\n        Planet(name=Venus, diameter=12104), \n        Planet(name=Earth, diameter=12742),\n        Planet(name=Mars, diameter=6779)      \n    ], \n    location=Solar System\n}\n```\n\nCalling `data.toRepr()`  would give us this:\n\n```kotlin\nmapOf(\n    \"planets\" to listOf(\n        Planet(name=\"Venus\", diameter=12104),\n        Planet(name=\"Earth\", diameter=12742),\n        Planet(name=\"Mars\", diameter=6779)\n    ), \n    \"location\" to \"Solar System\"\n)\n```\n\n*(both examples formatted for ease of reading)*\n\nThe library uses the features of Kotlin reflection. It is inspired by Python's built-in \n[`repr`]([https://docs.python.org/3/library/functions.html#repr]) function (and `__repr__` \noverloads). \n\n# Install [![Maven Central](https://img.shields.io/maven-central/v/io.github.rtmigo/repr.svg)](https://search.maven.org/artifact/io.github.rtmigo/repr)\n\n```kotlin\n// build.gradle.kts\n\ndependencies {\n    implementation(\"io.github.rtmigo:repr:X.X.X\")\n    // replace X.X.X with actual version\n}\n```\n\nFind the latest version and instructions for other build systems\nat [Maven Central](https://search.maven.org/artifact/io.github.rtmigo/repr).\n\n# Use\n\n```kotlin\nimport io.github.rtmigo.repr.toRepr\n\nfun main() {\n    val data = listOf(1, 2, 3)\n    println(data.toRepr())\n}\n```\n\nOutput:\n\n```kotlin\nlistOf(1, 2, 3)\n```\n\n## Customize .toRepr for your class\n\nThe `.toRepr()` extension method automatically converts `Any` objects.\n\nSometimes you may want to customize the way how your objects are converted. To do this,\ndefine `toRepr(): String` method for your class.\n\n```kotlin\nimport io.github.rtmigo.repr.toRepr\n\nclass TimeDefault(days: Int) {\n    val hours = days * 24\n}\n\nclass TimeTweaked(days: Int) {\n    val hours = days * 24\n    fun toRepr() = \"TimeTweaked(days=${hours / 24})\"\n}\n\nfun main() {\n    println(listOf(TimeDefault(days = 1), TimeDefault(days = 7)).toRepr())\n    println(listOf(TimeTweaked(days = 1), TimeTweaked(days = 7)).toRepr())\n}\n```\n\nOutput:\n\n```text\nlistOf(TimeDefault(hours=24), TimeDefault(hours=168))\nlistOf(TimeTweaked(days=1), TimeTweaked(days=7))\n```\n\u003csub\u003eSpecifying the `toRepr` method here is similar to overloading the `__repr__()` method in Python.\u003c/sub\u003e\n\n\n# License\n\nCopyright © 2022 [Artsiom iG](https://github.com/rtmigo).\nLicensed under the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0.txt).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frtmigo%2Frepr_kt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frtmigo%2Frepr_kt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frtmigo%2Frepr_kt/lists"}