Skip to content

Commit

Permalink
Merge pull request #743 from yomik/fix/duplicate_ctor_742
Browse files Browse the repository at this point in the history
Fix for #742 : Generating 2 constructors
  • Loading branch information
joelittlejohn authored Jun 13, 2017
2 parents 9d51e8c + 9056d5a commit ae1ba5a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,11 @@ private void addParcelSupport(JDefinedClass jclass) {
parcelableHelper.addDescribeContents(jclass);
parcelableHelper.addCreator(jclass);
parcelableHelper.addConstructorFromParcel(jclass);
// Add empty constructor
jclass.constructor(JMod.PUBLIC);
// #742 : includeConstructors will include the default constructor
if (!ruleFactory.getGenerationConfig().isIncludeConstructors()) {
// Add empty constructor
jclass.constructor(JMod.PUBLIC);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,22 @@ public void parcelableTreeIsParcelable() throws ClassNotFoundException, IOExcept

@Test
public void parcelableSuperclassIsUnparceled() throws ClassNotFoundException, IOException {
// Explicitely set includeConstructors to false if default value changes in the future
Class<?> parcelableType = schemaRule.generateAndCompile("/schema/parcelable/parcelable-superclass-schema.json", "com.example",
config("parcelable", true))
config("parcelable", true, "includeConstructors", false))
.loadClass("com.example.ParcelableSuperclassSchema");

Parcelable instance = (Parcelable) new ObjectMapper().readValue(ParcelableIT.class.getResourceAsStream("/schema/parcelable/parcelable-superclass-data.json"), parcelableType);
Parcel parcel = parcelableWriteToParcel(instance);
Parcelable unparceledInstance = parcelableReadFromParcel(parcel, parcelableType, instance);

assertThat(instance, is(equalTo(unparceledInstance)));
}

@Test
public void parcelableDefaultConstructorDoesNotConflict() throws ClassNotFoundException, IOException {
Class<?> parcelableType = schemaRule.generateAndCompile("/schema/parcelable/parcelable-superclass-schema.json", "com.example",
config("parcelable", true, "includeConstructors", true))
.loadClass("com.example.ParcelableSuperclassSchema");

Parcelable instance = (Parcelable) new ObjectMapper().readValue(ParcelableIT.class.getResourceAsStream("/schema/parcelable/parcelable-superclass-data.json"), parcelableType);
Expand Down

0 comments on commit ae1ba5a

Please sign in to comment.