rharter / auto-value-gson

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

Generalize support for setting properties with builders. #259

Closed eamonnmcmanus closed 3 years ago

eamonnmcmanus commented 3 years ago

AutoValue has a number of ways to set a property with a method whose parameter does not exactly match the return type of the property method. For example, a property defined by abstract ImmutableList<String> getFoo() can be set by an abstract method abstract Builder setFoo(List<String>). AutoValue knows how to implement this by calling ImmutableList.copyOf. Here, we don't need to know about ImmutableList.copyOf, we just need to know that this setter is indeed callable to set the value of the list. There are similar considerations for list builders (ImmutableList.Builder<String> fooBuilder()) and for Optional (Optional<String> set by plain String). This change allows auto-value-gson to use these alternative ways of setting a property, rather than requiring that the setter parameter exactly match the property type.

Also made two changes that should facilitate updating to newer JDKs and to newer versions of the Truth library: