Comments (13)
Released as 0.3.0
from auto-value-gson.
This looks pretty good to me. I implemented it, largely based on yours, in auto-value-moshi, with a few changes I would suggest for yours. You can check it out here: rharter/auto-value-moshi#30
Biggest difference is using the extension's applicable()
method so that logic is shared.
from auto-value-gson.
Are you working on this issue ? I would like to implement this feature.
from auto-value-gson.
I haven't gotten tarted on this yet, so you're welcome to take it. I appreciate it.
Only update I would make is calling itban AutoValueGsonTypeAdapter
. It's a mouthful, but we need to play nice with other extensions.
from auto-value-gson.
Thanks, I did not know whether you are working on it or not. I will start next week.
from auto-value-gson.
This does something similar:
https://github.com/evant/gsonvalue/blob/master/gsonvalue/src/main/java/me/tatarka/gsonvalue/ValueTypeAdapterFactory.java
The lookup of the generated TypeAdapters
is via reflection, though.
Is there a reason why two projects that combine GSON with AutoValue exist (this one and gsonvalue)? Just asking, because I'm undecided which one to choose, and the single type adapter factory seemed to be the difference up until now.
Btw +1 for supporting field naming policies.
from auto-value-gson.
That project is a fork, not an extension, so it won't work with other extensions, or new versions of AutoValue.
As for that example, a better approach (no reflection) is to add a second annotation processor that gathers all AutoValue annotated classes and statically generates a aTypeAdapterFactory containing them.
from auto-value-gson.
I believe you are confusing it with https://github.com/evant/auto-parcel-gson. It isn't an extension in the AutoValue sense, but I don't think it needs to be in order to play nice with other extensions or new versions.
Anyway, I agree that a statically generated TypeAdapterFactory would be a better solution. Looking forward to that.
from auto-value-gson.
Ahh, you're right. Looking close at that one (on my phone as I'm travelling) are you sure it's using AutoValue? It looks like it's a separate annotation processor entirely that processes a separate annotation (@GsonConstructor/@GsonBuilder).
from auto-value-gson.
It isn't using AutoValue directly. As in hooking into AutoValue's extensions mechanism. It compliments AutoValue by using the same rule set (accessor naming, builder pattern variant). At least that's what I understand.
from auto-value-gson.
@rharter I have small working example https://github.com/outlying/auto-value-gson/tree/feature/AnnotationProcessor
Some minor edge cases might not work but I added 'sample' module to present working example of annotation processing.
Processor will try to figure out with static method has proper signature (for TypeAdapter) so we don't need method naming convention.
from auto-value-gson.
Thanks, I didn't have much time to polish my code, but I am glad I could help in some way.
Only question why Moshi ? I respect Square libraries but this is not very common Json lib
from auto-value-gson.
Wow, that's great! Can't wait for release now, to drop my huge and boilerplate-ish adapter factory :)
from auto-value-gson.
Related Issues (20)
- Parse json object with varying data types
- RV_RETURN_VALUE_IGNORED findbugs error HOT 3
- Build failed in the generated read method for a generic class HOT 1
- Originating element not set HOT 3
- Generate proguard rules HOT 1
- Generic base types cause compile errors HOT 2
- Allow custom opt-in annotation for factory HOT 2
- AutoValueGsonExtension fails on immutable collections. HOT 1
- "Unable to get public no-arg constructor" simply when adding auto-value-gson dependency HOT 3
- auto-value-gson-from-rharter-generated-invalid-code HOT 6
- What dependency AutoValue annotation is in ? HOT 1
- Non-deterministic generation of TypeAdapterFactory HOT 2
- Issue using @GenerateTypeAdapter with maven HOT 2
- `@Nullable` doesn't work correctly with nested types
- NullPointerException processing ImmutableList.Builder Builder method
- Compilation error in Eclipse/maven
- Handling unrecognized json properties HOT 1
- @AutoValue.Builder generates objects with all fields HOT 2
- 也许这个方案更加好 HOT 1
- Could not instantiate annotation processor 'com.ryanharter.auto.value.gson.AutoValueGsonAdapterFactoryProcessor'
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from auto-value-gson.