{"id":21969507,"url":"https://github.com/rnett/exposedgson","last_synced_at":"2026-03-16T12:31:36.642Z","repository":{"id":67429751,"uuid":"152934670","full_name":"rnett/exposedgson","owner":"rnett","description":"GSON type adapter for Kotlin Exposed DAO classes.","archived":false,"fork":false,"pushed_at":"2019-03-26T00:43:02.000Z","size":77,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-27T12:52:31.661Z","etag":null,"topics":["dao","gson","json","kotlin","sql"],"latest_commit_sha":null,"homepage":null,"language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rnett.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2018-10-14T03:09:22.000Z","updated_at":"2020-01-14T18:48:22.000Z","dependencies_parsed_at":"2023-03-10T21:45:42.976Z","dependency_job_id":null,"html_url":"https://github.com/rnett/exposedgson","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rnett%2Fexposedgson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rnett%2Fexposedgson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rnett%2Fexposedgson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rnett%2Fexposedgson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rnett","download_url":"https://codeload.github.com/rnett/exposedgson/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251141827,"owners_count":21542429,"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":["dao","gson","json","kotlin","sql"],"created_at":"2024-11-29T14:21:32.991Z","updated_at":"2026-03-16T12:31:31.603Z","avatar_url":"https://github.com/rnett.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Version 1.1.1](https://img.shields.io/badge/version-1.1.1-green.svg)\n\n# Exposed GSON\n\nGson type adapters for [Kotlin Exposed](https://github.com/JetBrains/Exposed).\nFor use with Exposed DAO.\n\n## Warning\nThis is somewhat hacky, use at your own risk (reflection and casting).\nIt should work properly on valid DAO classes.\n\nIssues and improvements are welcome.\n\n## Install\n\nExposed GSON can be included using [JitPack](https://jitpack.io/#rnett/exposedgson).\n\n### Gradle\nIn gradle (kotlin script), it would look like this:\n```kotlin\nrepositories {\n    ...\n    maven(\"https://jitpack.io\")\n}\n\ndependencies {\n    ...\n    implementation(\"com.github.rnett:exposedgson:1.1.1\")\n}\n```\n\nFor other build tools, see the [JitPack site](https://jitpack.io/#rnett/exposedgson).\n\n## Usage\nTo use with a Exposed DAO class, add the annotation `@JsonAdapter(ExposedTypeAdapter::class)`.\nE.x.:\n```kotlin\n@JsonAdapter(ExposedTypeAdapter::class)\nclass account(id: EntityID\u003cInt\u003e) : IntEntity(id){\n```\n\nThen, if you use `Gson().toJson()` (or any other serialization methods) on an instance of your entity,\nit will be serialized using Exposed GSON's type adapter.\n\nThe JSON will only include declared properties, along with a database id.\n\n**Note that it will also include properties that wouldn't normally show up in GSON JSON data.**\n\nBy default, this id is the `id` property of the `Entity` superclass, and is stored in the JSON field `$$database_id$$`.\nHowever, these are both changeable; see `@ExposedGSON.UseAsID` and `@ExposedGSON.JsonDatabaseIdField`.\n\n**When parsing JSON, Exposed GSON only looks at the database id, then pulls the entity from the database.**\n\nChanges made in the JSON will not be reflected in the parsed object or in the database (this is something I may add in the future).\n\n**Note that seraliziation and parsing must be done inside Exposed transactions.**\n\n## Annotations\n\nExposed GSON provides a number of annotations to customize the JSON representation of the entity.\nThese are `@ExposedGSON.JsonName`, `@ExposedGSON.Ignore`, `@ExposedGSON.UseAsID`, and `@ExposedGSON.JsonDatabaseIdField`.\n\n### @ExposedGSON.JsonName\n\n`@ExposedGSON.JsonName` can be applied to properties.\nIt takes a string as a parameter, and uses that string as the property name in the JSON.\nE.x.:\n```kotlin\n@ExposedGSON.JsonName(\"this_email\")\nvar email by accounts.email\n```\n`email` will then be represented by the JSON field `this_email`.\n\n### @ExposedGSON.Ignore\n\n`@ExposedGSON.Ignore` can be applied to properties.\nIt is simple: if it is present, the property will not be included in the JSON.\nE.x.:\n```kotlin\n@ExposedGSON.Ignore\nvar pwHash by accounts.pwHash\n```\n`pwHash` will then not be included in the JSON.\n\n### @ExposedGSON.UseAsID\n\n`@ExposedGSON.UseAsID` can be applied to properties (only one per class).\nIt tells Exposed GSON to use that property as the entity id when creating the object.\n\n**When parsing JSON, Exposed GSON will pass the value of this property to the entity class's `findById` method to generate the entity from the database.**\nMake sure this is the intended behavior.\n\nWhen this annotation is present, Exposed GSON will not create a separate database id field in the JSON.\n\nIf this annotation is present more than once in a class, an exception will be thrown.\n\nThis annotation will work with `@ExposedGSON.JsonName`.\n\nE.x.:\n```kotlin\nobject accounts : IntIdTable(\"accounts\", \"accountid\") {\n\n    // Database Columns\n\n    val accountid = integer(\"accountid\").autoIncrement().primaryKey()\n\n    ...\n}\n\n@JsonAdapter(ExposedTypeAdapter::class)\nclass account(id: EntityID\u003cInt\u003e) : IntEntity(id) {\n    @ExposedGSON.UseAsID\n    val accountid by accounts.accountid\n\n    ...\n}\n```\n\n`accountid` will then be used in place of the special id field in the JSON.\n\nNote that `accountid` is the primary key of the table, and is the correct type for `findById`\n\n### @ExposedGSON.JsonDatabaseIdField\n`@ExposedGSON.JsonDatabaseIdField` can be applied to the DAO class.\nIt is meaningless unless `@JsonAdapter(ExposedTypeAdapter::class)` is also used.\n\n`@ExposedGSON.JsonDatabaseIdField` takes a string, and uses that string as the name of the special id field in the JSON (instead of `$$database_id$$`).\n\nIf both `@ExposedGSON.JsonDatabaseIdField` and `@ExposedGSON.UseAsID` are present, an exception will be thrown.\n\nE.x.:\n```kotlin\n@JsonAdapter(ExposedTypeAdapter::class)\n@ExposedGSON.JsonDatabaseIdField(\"this_id\")\nclass account(id: EntityID\u003cInt\u003e) : IntEntity(id) {\n    ...\n}\n```\nThen `this_id` will be used as the id field in the JSON, instead of `$$database_id$$`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frnett%2Fexposedgson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frnett%2Fexposedgson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frnett%2Fexposedgson/lists"}