You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2022-09-26T16:08:14.239092+03:00[Europe/Bucharest]")
publicclassTestObject {
@JsonProperty("nullableString")
privateJsonNullable<String> nullableString = JsonNullable.undefined();
@JsonProperty("picture")
privateJsonNullable<byte[]> picture = JsonNullable.undefined();
publicTestObjectnullableString(StringnullableString) {
this.nullableString = JsonNullable.of(nullableString);
returnthis;
}
/** * Get nullableString * @return nullableString */@Schema(name = "nullableString", required = false)
publicJsonNullable<String> getNullableString() {
returnnullableString;
}
publicvoidsetNullableString(JsonNullable<String> nullableString) {
this.nullableString = nullableString;
}
publicTestObjectpicture(byte[] picture) {
this.picture = JsonNullable.of(picture);
returnthis;
}
/** * Get picture * @return picture */@Schema(name = "picture", required = false)
publicJsonNullable<byte[]> getPicture() {
returnpicture;
}
publicvoidsetPicture(JsonNullable<byte[]> picture) {
this.picture = picture;
}
@Overridepublicbooleanequals(Objecto) {
if (this == o) {
returntrue;
}
if (o == null || getClass() != o.getClass()) {
returnfalse;
}
TestObjecttestObject = (TestObject) o;
returnObjects.equals(this.nullableString, testObject.nullableString) &&
Arrays.equals(this.picture, testObject.picture);
}
privatestatic <T> booleanequalsNullable(JsonNullable<T> a, JsonNullable<T> b) {
returna == b || (a != null && b != null && a.isPresent() && b.isPresent() && Objects.deepEquals(a.get(), b.get()));
}
@OverridepublicinthashCode() {
returnObjects.hash(nullableString, Arrays.hashCode(picture));
}
privatestatic <T> inthashCodeNullable(JsonNullable<T> a) {
if (a == null) {
return1;
}
returna.isPresent() ? Arrays.deepHashCode(newObject[]{a.get()}) : 31;
}
@OverridepublicStringtoString() {
StringBuildersb = newStringBuilder();
sb.append("class TestObject {\n");
sb.append(" nullableString: ").append(toIndentedString(nullableString)).append("\n");
sb.append(" picture: ").append(toIndentedString(picture)).append("\n");
sb.append("}");
returnsb.toString();
}
/** * Convert the given object to string with each line indented by 4 spaces * (except the first line). */privateStringtoIndentedString(Objecto) {
if (o == null) {
return"null";
}
returno.toString().replace("\n", "\n ");
}
}
As you can see the equalsNullable method is not being used, instead it is being used the Arrays.equals().
Similarly Objects.equals() is being used instead of equalsNullable for other properties I try to add.
Related issues/PRs
I've done some searches and seems that the issue was fixed with this commit: #10012
However, I tried also generating the same output with version 5.2.0 - which seems to be the one that contains the fix and I have the same results.
Something is clearly missing/faulty.
Edit: Gave more details and a simplified example.
The text was updated successfully, but these errors were encountered:
mariusmanastireanu
changed the title
[BUG][Java] JsonNullable with primitive array type results in compilation error in equals() method
[BUG][Java] Generated Java POJOs with JsonNullable do not use equalsNullable in generated equals method
Sep 26, 2022
* Fixing to use equalsNullable when nullable set in config for SpringCodeGen
* Adding additional test case file
* removed print statement from SpringCodeGen
* Updated model object
* Corrected indentation and removed import
* Fixed broken test
* Updating sample
Bug Report Checklist
Description
I am trying to generate an object with a property of nullable primitive array type and the code generated does not match my description.
openapi-generator version
5.2.0, 6.0.1, 6.2.0
OpenAPI declaration file content or url
Generation Details
I'm using this in a Spring-Boot project with the following configuration:
This generates the following java class:
As you can see the
equalsNullable
method is not being used, instead it is being used theArrays.equals()
.Similarly
Objects.equals()
is being used instead ofequalsNullable
for other properties I try to add.Related issues/PRs
I've done some searches and seems that the issue was fixed with this commit: #10012
However, I tried also generating the same output with version 5.2.0 - which seems to be the one that contains the fix and I have the same results.
Something is clearly missing/faulty.
Edit: Gave more details and a simplified example.
The text was updated successfully, but these errors were encountered: