rharter / auto-value-gson

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

auto-value-gson-from-rharter-generated-invalid-code #252

Closed CodeMasterMo closed 3 years ago

CodeMasterMo commented 4 years ago

We are using https://github.com/rharter/auto-value-gson to generate the TypeAdapter for our @AutoValue objects.

For Animal class

@AutoValue abstract class Animal { abstract String name();

abstract int numberOfLegs();

static Builder builder() {
    return new AutoValue_Animal.Builder();
}

public static TypeAdapter<Animal> typeAdapter(Gson gson) {
    return new AutoValue_Animal.GsonTypeAdapter(gson);
}

@AutoValue.Builder
abstract static class Builder {
    abstract Builder setName(String value);

    abstract Builder setNumberOfLegs(int value);

    abstract Animal build();
}

} The code is generated with this part at the end

@Override @SuppressWarnings("unchecked") public Animal read(JsonReader jsonReader) throws IOException { ... ..

 jsonReader.endObject();
  return builder.abstract com.project.Animal build();

} Shouldn't this be builder.build();

We are using eclipse to build the code and compile to java 8.

Does anyone has any tips how to solve this?

mseele commented 3 years ago

@rharter i've added a PL to fix this issue. Would you mind to release a new version?

mseele commented 3 years ago

@rharter thank's for applying the pl. Is there any timeline you will release a new version (1.4?) and push it to maven repositories?

rharter commented 3 years ago

You should see 1.3.1 in central.

mseele commented 3 years ago

You should see 1.3.1 in central.

I don't see it

Am I looking on the wrong repositories?

rharter commented 3 years ago

Sorry about that, @mseele, I must've gotten distracted. It's syncing up now.

mseele commented 3 years ago

@rharter There is only a 1.3.1 in central for auto-value-gson-runtime, but my fix was in auto-value-gson-extension. Would you mind release a 1.3.1 for auto-value-gson-extension, too? Thank you!