{"id":13766173,"url":"https://github.com/gabrielittner/auto-value-cursor","last_synced_at":"2025-05-10T21:33:09.009Z","repository":{"id":48329195,"uuid":"41223379","full_name":"gabrielittner/auto-value-cursor","owner":"gabrielittner","description":"AutoValue extension to create an AutoValue object from a Cursor","archived":true,"fork":false,"pushed_at":"2021-07-26T04:19:40.000Z","size":397,"stargazers_count":171,"open_issues_count":0,"forks_count":20,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-11-17T02:33:43.562Z","etag":null,"topics":["android","autovalue","autovalue-extension"],"latest_commit_sha":null,"homepage":"","language":"Java","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/gabrielittner.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-08-22T20:33:59.000Z","updated_at":"2024-02-26T15:05:02.000Z","dependencies_parsed_at":"2022-08-26T02:23:07.537Z","dependency_job_id":null,"html_url":"https://github.com/gabrielittner/auto-value-cursor","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gabrielittner%2Fauto-value-cursor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gabrielittner%2Fauto-value-cursor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gabrielittner%2Fauto-value-cursor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gabrielittner%2Fauto-value-cursor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gabrielittner","download_url":"https://codeload.github.com/gabrielittner/auto-value-cursor/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253486190,"owners_count":21916133,"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":["android","autovalue","autovalue-extension"],"created_at":"2024-08-03T16:00:52.259Z","updated_at":"2025-05-10T21:33:08.642Z","avatar_url":"https://github.com/gabrielittner.png","language":"Java","funding_links":[],"categories":["Database"],"sub_categories":[],"readme":"# AutoValue: Cursor Extension\n\nAn extension for Google's [AutoValue][auto] that generates a `createFromCursor(Cursor c)` method for AutoValue annotated objects.\n\n\n## Usage\n\nInclude auto-value-cursor in your project and add a static factory method to your auto-value object.\n\n```java\nimport com.gabrielittner.auto.value.cursor.ColumnName;\n\n@AutoValue public abstract class User {\n  abstract String id();\n  abstract String name();\n  // use the annotation if column name and field name aren't the same\n  @ColumnName(\"email_address\") abstract String email();\n\n  public static User create(Cursor cursor) {\n    return AutoValue_User.createFromCursor(cursor);\n  }\n\n  // Optional: if your project includes RxJava the extension will generate a Func1\u003cCursor, User\u003e\n  public static Func1\u003cCursor, User\u003e MAPPER = AutoValue_User.MAPPER;\n\n  // Optional: if your project includes RxJava 2 the extension will generate a Function\u003cCursor, User\u003e\n  public static Function\u003cCursor, User\u003e MAPPER = AutoValue_User.MAPPER_FUNCTION;\n\n  // Optional: When you include an abstract method that returns ContentValues and doesn't have\n  // any parameters the extension will implement it for you\n  abstract ContentValues toContentValues();\n}\n```\n\n**Important:** The extension will only be applied when there is\n- a static method that returns your value type (`User` in the example) and takes a `Cursor` as parameter\n- and/or a static field of type `Func1\u003cCursor, YourValueType\u003e`\n- and/or a static field of type `Function\u003cCursor, YourValueType\u003e`\n\n## Custom types\n\nThe following types are supported by default:\n\n * `byte[]`\n * `double`/`Double`\n * `float`/`Float`\n * `int`/`Integer`\n * `long`/`Long`\n * `short`/`Short`\n * `String`\n * `boolean`/`Boolean`\n\nFor other types, you need to use the `@ColumnAdapter` annotation and specify a factory\nclass that implements the `ColumnTypeAdapter` interface.\nWhen you need to map multiple columns to one custom type you can simply ignore the given\n`columnName`. Eg.:\n\n`User.java`:\n\n```java\n@AutoValue public abstract class User {\n  abstract String id();\n  abstract String name();\n  @ColumnAdapter(AvatarAdapter.class) Avatar avatar();\n\n  public static User createFromCursor(Cursor cursor) {\n    return AutoValue_User.createFromCursor(cursor);\n  }\n}\n```\n\n`AvatarAdapter.java`:\n\n```java\npublic class AvatarAdapter implements ColumnTypeAdapter\u003cAvatar\u003e {\n  public Avatar fromCursor(Cursor cursor, String columnName) {\n    String smallImageUrl = cursor.getString(cursor.getColumnIndex(\"small_image_url\");\n    String largeImageUrl = cursor.getString(cursor.getColumnIndex(\"large_image_url\");\n    return new Avatar(smallImageUrl, largeImageUrl);\n  }\n  public void toContentValues(ContentValues values, String columnName, Avatar value) {\n    // leave this empty when you don't use a \"toContentValues()\" method\n    values.putString(\"small_image_url\", value.smallImageUrl);\n    values.putString\"large_image_url\", value.largeImageUrl);\n  }\n}\n```\n\n`Avatar.java`:\n\n```java\npublic class Avatar {\n  final String smallImageUrl;\n  final String largeImageUrl;\n\n  public Avatar(String smallImageUrl, String largeImageUrl) {\n    this.smallImageUrl = smallImageUrl;\n    this.largeImageUrl = largeImageUrl;\n  }\n}\n```\n\n## Download\n\nAdd a Gradle dependency:\n\n```groovy\nannotationProcessor 'com.gabrielittner.auto.value:auto-value-cursor:2.0.1'\n// if you need the @ColumnName or @ColumnAdapter annotations also include this:\nimplementation 'com.gabrielittner.auto.value:auto-value-cursor-annotations:2.0.1'\n```\n\nSnapshots of the development version are available in [Sonatype's `snapshots` repository][snap].\n\n## License\n\nThis project is heavily based on [Ryan Harter][ryan]'s [auto-value-gson][auto-gson]\n\n```\nCopyright 2015 Ryan Harter.\nCopyright 2015 Gabriel Ittner.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n   http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n\n\n\n [auto]: https://github.com/google/auto\n [snap]: https://oss.sonatype.org/content/repositories/snapshots/\n [ryan]: https://github.com/rharter/\n [auto-gson]: https://github.com/rharter/auto-value-gson\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgabrielittner%2Fauto-value-cursor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgabrielittner%2Fauto-value-cursor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgabrielittner%2Fauto-value-cursor/lists"}