Upgrade to Pro — share decks privately, control downloads, hide ads and more …

AutoValue for Easier Life

AutoValue for Easier Life

AutoVaulue is a library that generates Immutable value-type codes for Java 1.6+, maintained by Google, inc.

I have talked about AutoValue and AutoValue Extensions in general and some pros and cons that my team and I have figured out while developing our up with AutoValue.

While AutoValue is not applicable for ALL applications in general (For example, in Kotlin?), I am sure it may help most of the developers make their development a lot easier with scalable, maintainable generated codes and possibly additional performance optimization.

* auto/value at master · google/auto
https://github.com/google/auto/tree/master/value

* An Introduction to AutoValue
http://ryanharter.com/blog/2016/03/22/autovalue/

* A Deeper Look at AutoValue - Ryan Harter

http://ryanharter.com/blog/2016/04/08/autovalue-deep-dive/

* AutoValue Extensions - Ryan Harter

http://ryanharter.com/blog/2016/05/16/autovalue-extensions/

* AutoValue Extensions - Jake Wharton

http://jakewharton.com/auto-value-extensions-ny-android-meetup/

* Faster JSON Deserialization with AutoValue GSON extension
http://dubedout.eu/2016/07/11/faster-json-deserialization-autovalue-extension/

Shohei Kawano

July 28, 2016
Tweet

More Decks by Shohei Kawano

Other Decks in Programming

Transcript

  1. (One of the)
 Oldest App in CyberAgent, Inc. Own Abstraction,

    Unique Implementation New Team Members Inconsistency Codes Throughout the App Writing Tests, Removing Tests Unknown Specification
  2. For Starting Out, We’d like to do 2 things. 2.

    Avoid Writing Boilerplate Codes 1. Remove Boilerplate Codes
  3. Add New Field? Remove New Field? Inner Classes with Parcelable?

    Adding New Parcelable Tests? Removing Parcelable Tests?
  4. Usage // root dependencies { classpath ‘com.neenbedankt.gradle.plugins:android-apt:1.8’ … } …

    // app dependencies { provided 'com.google.auto.value:auto-value:1.3-rc2' }
  5. AutoValue • Add @AutoValue to make objects value- typed using

    generated boilerplate codes • Add @AutoValue.Builder to create Builder class for your auto-value object
  6. AutoValue • Add @AutoValue to make objects value- typed using

    generated boilerplate codes • Add @AutoValue.Builder to create Builder class for your auto-value object
  7. AutoValue • Add @AutoValue to make objects value- typed using

    generated boilerplate codes • Add @AutoValue.Builder to create Builder class for your auto-value object • AutoValue Extension support for 
 Parcelable, Gson, Moshi, Cursor, and more..
  8. Usage(auto-value-parcel) // root dependencies { classpath ‘com.neenbedankt.gradle.plugins:android-apt:1.8’ … } …

    // app dependencies { provided ‘com.google.auto.value:auto-value:1.3-rc2' // auto-value-parcel apt 'com.ryanharter.auto.value:auto-value-parcel:0.2.3-rc2' }
  9. Usage(auto-value-parcel) // root dependencies { classpath ‘com.neenbedankt.gradle.plugins:android-apt:1.8’ … } …

    // app dependencies { provided ‘com.google.auto.value:auto-value:1.3-rc2' // auto-value-parcel apt 'com.ryanharter.auto.value:auto-value-parcel:0.2.3-rc2' }
  10. “With-er” auto-value-with public abstract SomeValue withNewId(String newId); @Override public final

    SomeValue withNewId(String newId) { return new AutoValue_SomeValue(newId); } Generated Code:
  11. “With-er” auto-value-with public abstract SomeValue withNewId(String newId); @Override public final

    SomeValue withNewId(String newId) { return new AutoValue_SomeValue(newId); } Generated Code:
  12. auto-value-gson // The public static method returning a TypeAdapter<Foo> is

    what // tells auto-value-gson to create a TypeAdapter for Foo. public static TypeAdapter<Foo> typeAdapter(Gson gson) { return new AutoValue_Foo.GsonTypeAdapter(gson); } } final Gson gson = new GsonBuilder() .registerTypeAdapterFactory(new AutoValueGsonTypeAdapterFactory()) .create(); https://github.com/rharter/auto-value-gson