rharter / auto-value-gson

AutoValue Extension to add Gson De/Serializer support
Apache License 2.0
607 stars 103 forks source link

Support property defaults, normalization, and validation via Builder #136

Closed bryanstern closed 5 years ago

bryanstern commented 7 years ago

This is a first pass at implementing a solution for #132 using the proposed AutoValue builder properties google/auto#501.

If an AutoValue class specifies a builder with the @AutoValue.Builder annotation, the generated TypeAdapter#read implementation will make use of the builder. If the builder performs any normalization or validation, it will run.

The TypeAdapter default setters have been removed as builders allow the user to specify defaults using the AutoValue convention. Annotate the builder() method with @GsonDefaultBuilder to specify which method AutoValueGson should use to get an instance of the builder.

If your builder specifies multiple build() or unconventional build methods (not named build), you indicate which method in the Builder should be used with @GsonBuild.

bryanstern commented 7 years ago

Incorporated your feedback. I totally agree we should infer the static builder() methods where we can and be less picky about build vs create.

liujoshua commented 6 years ago

Any updates on this? I'm using @AutoValue.Builder and providing default/initial values on the builder, e.g. empty Guava Immutable collections.

bryanstern commented 6 years ago

@liujoshua still blocked on the AutoValue project. https://github.com/google/auto/pull/501

bryanstern commented 5 years ago

Closing this in favor of #224