AutoValue Extensions - Ryan Harter
In a previous article introducing AutoValue, I briefly mentioned AutoValue Extensions. Now it's time to go a bit more in depth to look at what extensions are, how they work, and how they can help you get even more out of AutoValue.
What are AutoValue Extenions
As mentioned in the last article, AutoValue is a compile time code generator that generates all of the boilerplate code to enable immutable value types in Java. Extensions tie into this compile time generation and allow you to easily add functionality to these value types.
While AutoValue does a great job of creating value types, those value types are rarely used in isolation. Most apps interact with multiple libraries and services using these value types. These can be web services, which might serialize value types using JSON or Protocol Buffers, databases, and Androids Parcelable interface. AutoValue has no support for these protocols built in, since it is a focused library, and there's no way to know which services users might use.
To provide support for unknown services, or provide customization to the generated code, AutoValue 1.2 introduced Extensions. By including an AutoValue extension in your dependencies, you can add functionality to the generated AutoValue value types, usually with minimal work from you.
Read full article from AutoValue Extensions - Ryan Harter
No comments:
Post a Comment