Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support generating external adapters #146

Merged
merged 13 commits into from
Jan 12, 2020
Merged

Conversation

ZacSweers
Copy link
Collaborator

Resolves #119

This uses moshi's native generated adapter lookup mechanism. To use, simply annotate the autovalue class with @JsonClass(generateAdapter = true, generator = "avg") and then auto-value-moshi will generate a top-level adapter.

README.md Outdated
using `@Json` to define an alternate name for de/serialization.
Simply include auto-value-moshi in your project and annotate your target autovalue class with Moshi's
`@JsonClass` annotation. `generateAdpater` must be true, and the `generator` property value should
be `"avg"`.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be "autovalue", or at least "avm", right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

d'oh, fixed avm

Copy link
Owner

@rharter rharter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice.

This gets me wondering if there's a way for the generator property to be inferred, like a service locator in Moshi that effectively tries to find services that can generate the adapter, in this case AVM providing a generator for classes that are @JsonClass and @AutoValue annotated, otherwise falling back to it's own internal generator. That is most definitely a nice-to-have that's out of this scope, though, and possible not even worth it.

@ZacSweers
Copy link
Collaborator Author

Possibly! R8 does support inlining servicelocator lookups so it's something we could look at. Will file an issue

@ZacSweers ZacSweers merged commit eece4e2 into master Jan 12, 2020
@ZacSweers ZacSweers deleted the z/originatingElementFix branch January 12, 2020 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support generation of adapters outside of autovalue class hierarchy
2 participants