{"id":17065994,"url":"https://github.com/lachlanmckee/gsonpath","last_synced_at":"2025-09-05T13:40:05.057Z","repository":{"id":57737334,"uuid":"53666769","full_name":"LachlanMcKee/gsonpath","owner":"LachlanMcKee","description":"A Java annotation processor library which generates gson type adapters using basic JsonPath style annotations","archived":false,"fork":false,"pushed_at":"2020-04-17T13:27:06.000Z","size":1415,"stargazers_count":61,"open_issues_count":6,"forks_count":4,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-12T18:42:24.991Z","etag":null,"topics":["adapter-factory","android","annotation-processor","annotation-processor-library","annotations","gson","java","java-annotation-processor","json","jsonpath","kotlin"],"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/LachlanMcKee.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":"2016-03-11T12:50:37.000Z","updated_at":"2024-08-08T11:50:02.000Z","dependencies_parsed_at":"2022-08-24T06:00:16.905Z","dependency_job_id":null,"html_url":"https://github.com/LachlanMcKee/gsonpath","commit_stats":null,"previous_names":[],"tags_count":51,"template":false,"template_full_name":null,"purl":"pkg:github/LachlanMcKee/gsonpath","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LachlanMcKee%2Fgsonpath","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LachlanMcKee%2Fgsonpath/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LachlanMcKee%2Fgsonpath/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LachlanMcKee%2Fgsonpath/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LachlanMcKee","download_url":"https://codeload.github.com/LachlanMcKee/gsonpath/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LachlanMcKee%2Fgsonpath/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273766993,"owners_count":25164459,"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-05T02:00:09.113Z","response_time":402,"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":["adapter-factory","android","annotation-processor","annotation-processor-library","annotations","gson","java","java-annotation-processor","json","jsonpath","kotlin"],"created_at":"2024-10-14T11:05:34.663Z","updated_at":"2025-09-05T13:40:04.987Z","avatar_url":"https://github.com/LachlanMcKee.png","language":"Kotlin","readme":"# Gson Path\n\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/net.lachlanmckee/gsonpath/badge.svg)](https://maven-badges.herokuapp.com/maven-central/net.lachlanmckee/gsonpath) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-gsonpath-green.svg?style=true)](https://android-arsenal.com/details/1/4191)\n\nAn annotation processor library which generates gson type adapters at compile time which also use basic JsonPath functionality.\n\n## Benefits\nThe benefits of this library are as follows:\n\n#### Statically generated Gson Type Adapters\nBy statically generating Gson Type Adapters, the majority of reflection used by the Gson library can be removed. This greatly improves performance and removes code obfuscation issues.\n\n#### JsonPath syntax\nJsonPath syntax can be used to reduce the number of POJOs required to parse a JSON file. See the example section for more details.\n\nThis allows for easier integration with other libraries which rely on a flat class structure (such as DBFlow).\n\n#### POJO immutability via interfaces\nYou are given the option of using immutable POJOs based off annotated interfaces.\n\nThese POJOs are similar to AutoValue, however you do not need to reference the concrete implementation as the Type Adapter creates it on your behalf.\n\nSee the [interfaces guide](guides/interfaces.md) for further details.\n\n#### JsonPath - Path Substitutions\nYou can reduce the amount of repetition when creating POJOs using Path Substitutions by using straightforward string replacement functionality within the `AutoGsonAdapter` annotation.\n\nSee the [path substitution guide](guides/path_substitution.md) for further details.\n\n#### Optional client side validation\nAdd optional client side validation to your json using `@Nullable` and `NonNull` annotations to add mandatory field constraints.\n\nThe client side valiation can also be enhanced through extensions. These extensions are separate annotation processors that register to be notified whenever a field with a specific annotation is encountered.\n\n##### Notable extensions\n[Android Support Annotation validation](https://github.com/LachlanMcKee/gsonpath-extensions-android)\n\n## Example\nGiven the following JSON:\n\n```json\n{\n   \"person\": {\n      \"names\": {\n         \"first\": \"Lachlan\",\n         \"last\": \"McKee\"\n      }\n   }\n}\n```\n\nWe can deserialize the content with a single class by using Gson Path. The following class demonstrates the annotations required to create a type adapter which can correctly read the content.\n\n```java\n@AutoGsonAdapter(rootField = \"person.names\")\npublic class PersonModel {\n   @SerializedName(\"first\")\n   String firstName;\n   \n   @SerializedName(\"last\")\n   String lastName;\n}\n```\n\nWe could also write it as follows (to reduce the number of annotations required):\n\n```java\n@AutoGsonAdapter(rootField = \"person.names\")\npublic class PersonModel {\n   String first;\n   String last;\n}\n```\n\n## Setup\nThe following steps are required to use the generated `TypeAdapters` within your project.\n\n#### AutoGsonAdapterFactory\nCreate a type adapter factory by annotating an interface as follows:\n\n```java\npackage com.example;\n \n@AutoGsonAdapterFactory\npublic interface ExampleGsonTypeFactory extends TypeAdapterFactory {\n}\n```\n\nGson Path can be used across multiple modules by defining a factory within each. \n\n*Note: Only one `@AutoGsonAdapterFactory` annotation may be used per module/project. If you do this accidentally, the annotation processor will raise a helpful error.*\n\n#### AutoGsonAdapter\nCreate any number of type adapters by annotating a class or interface as follows:\n\n```java\npackage com.example;\n \n@AutoGsonAdapter\npublic class ExampleModel {\n    String value;\n}\n```\n\nor\n\n```java\npackage com.example;\n \n@AutoGsonAdapter\npublic interface ExampleModel {\n    String getValue();\n}\n```\n\n#### Gson Integration\nFor each type adapter factory interface, register it with your Gson builder as follows:\n\n```java\nreturn new GsonBuilder()\n                .registerTypeAdapterFactory(GsonPath.createTypeAdapterFactory(ExampleGsonTypeFactory.class))\n                .create();\n```\n\n#### Incremental annotation processing\n\nYou must update your build.gradle (for each module) to opt into incremental annotation processing.\n\nWhen enabled, all custom annotations (annotations which are either themselves annotated with either: `@AutoGsonAdapter`, `@GsonSubType`, `@AutoGsonAdapterFactory`) must be registered in the build.gradle (comma separated), otherwise they will be silently ignored.\n\nExamples of this configuration are as follows: \n\n```groovy\n// Standard annotation processor\njavaCompileOptions {\n   annotationProcessorOptions {\n      arguments = [\n         'gsonpath.incremental': 'true',\n         'gsonpath.additionalAnnotations': 'com.example.CustomAutoGsonAdapter,com.example.CustomGsonSubType'\n      ]\n   }\n}\n\n// Kotlin annotation processor (kapt)\nkapt {\n   arguments {\n      arg(\"gsonpath.incremental\", \"true\")\n      arg(\"gsonpath.additionalAnnotations\", \"com.example.CustomAutoGsonAdapter,com.example.CustomGsonSubType\")\n   }\n}\n```\n\n## Proguard\nTo use proguard within your project, you must add the generated type adapter factory. Using the example above, this would be:\n\n```\n-keep public class com.example.ExampleGsonTypeFactoryImpl\n```\n\n## Download\nThis library is available on Maven, you can add it to your project using the following gradle dependencies:\n\n```gradle\ncompile 'net.lachlanmckee:gsonpath:4.0.0'\napt 'net.lachlanmckee:gsonpath-compiler:4.0.0'\n\ncompile 'net.lachlanmckee:gsonpath-kt:4.0.0' // an optional Kotlin library \n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flachlanmckee%2Fgsonpath","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flachlanmckee%2Fgsonpath","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flachlanmckee%2Fgsonpath/lists"}