https://github.com/techery/immutables-gson-adapters-provider
Annotation Processor to generate List of generated Gson's TypeAdapterFactory(s) for Immutables.org
https://github.com/techery/immutables-gson-adapters-provider
gson immutables processing
Last synced: 16 days ago
JSON representation
Annotation Processor to generate List of generated Gson's TypeAdapterFactory(s) for Immutables.org
- Host: GitHub
- URL: https://github.com/techery/immutables-gson-adapters-provider
- Owner: techery
- Created: 2017-06-23T14:55:50.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-06-26T18:24:36.000Z (almost 9 years ago)
- Last Synced: 2025-10-29T06:39:21.741Z (7 months ago)
- Topics: gson, immutables, processing
- Language: Java
- Size: 57.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Immutables.org Gson Adapters Provider
Annotation Processor to aggregate all generated `Gson`'s `TypeAdapterFactory`(s) by [Immutables.org](http://immutables.github.io/json.html)
## What is it for?
[Immutables.org](http://immutables.github.io/) is handy for models and [Gson](https://github.com/google/gson) type adapters generation,
the problems is you have to register all auto-generated adapters manually
– that's where the processor comes in: it creates simple class to provide `Collection` of `TypeAdapterFacotory`.
## Usage & Installation
```java
GsonBuilder gsonBuilder = new GsonBuilder();
for (TypeAdapterFactory immutablesFactory : new ImmutablesGsonAdaptersProvider().getAdapters()) {
gsonBuilder.registerTypeAdapterFactory(immutablesFactory);
}
Gson gson = gsonBuilder.create();
```
[](https://jitpack.io/#techery/immutables-gson-adapters-provider)
[](https://travis-ci.org/techery/immutables-gson-adapters-provider)
```groovy
repositories {
maven { url "https://jitpack.io" }
}
compileJava { // optionally
options.compilerArgs += '-Aorg.immutables.gson.adapter.package=org.immutables.gson.adapter.util'
options.compilerArgs += '-Aorg.immutables.gson.adapter.provider_name=ImmutablesGsonAdaptersProvider'
}
dependencies {
apt 'com.github.techery:immutables-gson-adapters-provider:$version'
}
```
## Caveats
Processor uses only 1 round of annotation processing and while you don't generate interfaces for immutables (to generate models upon) it should be okey.
The most solid solution would involve some gradle plugin to operate with classes generated by every possible round of processing, but is another story.
Also, Immutables.org generates `META-INF/services` file so possibly could be used by `ServiceLoader` but it's not a reliable solution for `android` and could cause performance penalty.
## Credits
Thanks to [Immutables.org](http://immutables.github.io/) for their constantly improving library and [@devanatolii](https://github.com/DevAnatolii) for basic processor implementation.
## License
Copyright (c) 2017 Techery
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.