mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-09 08:26:11 +00:00
[Java] fix nullable arrays when JsonNullable is used (#10012)
This commit is contained in:
@@ -26,6 +26,7 @@ import org.openapitools.client.model.OuterEnum;
|
||||
import org.openapitools.client.model.OuterEnumDefaultValue;
|
||||
import org.openapitools.client.model.OuterEnumInteger;
|
||||
import org.openapitools.client.model.OuterEnumIntegerDefaultValue;
|
||||
import org.openapitools.jackson.nullable.JsonNullable;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import org.openapitools.jackson.nullable.JsonNullable;
|
||||
import java.util.NoSuchElementException;
|
||||
@@ -453,15 +454,28 @@ public class EnumTest {
|
||||
Objects.equals(this.enumStringRequired, enumTest.enumStringRequired) &&
|
||||
Objects.equals(this.enumInteger, enumTest.enumInteger) &&
|
||||
Objects.equals(this.enumNumber, enumTest.enumNumber) &&
|
||||
Objects.equals(this.outerEnum, enumTest.outerEnum) &&
|
||||
equalsNullable(this.outerEnum, enumTest.outerEnum) &&
|
||||
Objects.equals(this.outerEnumInteger, enumTest.outerEnumInteger) &&
|
||||
Objects.equals(this.outerEnumDefaultValue, enumTest.outerEnumDefaultValue) &&
|
||||
Objects.equals(this.outerEnumIntegerDefaultValue, enumTest.outerEnumIntegerDefaultValue);
|
||||
}
|
||||
|
||||
private static <T> boolean equalsNullable(JsonNullable<T> a, JsonNullable<T> b) {
|
||||
return a == b || (a != null && b != null && a.isPresent() && b.isPresent() && a.get().getClass().isArray() ? Arrays.equals((T[])a.get(), (T[])b.get()) : Objects.equals(a.get(), b.get()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(enumString, enumStringRequired, enumInteger, enumNumber, outerEnum, outerEnumInteger, outerEnumDefaultValue, outerEnumIntegerDefaultValue);
|
||||
return Objects.hash(enumString, enumStringRequired, enumInteger, enumNumber, hashCodeNullable(outerEnum), outerEnumInteger, outerEnumDefaultValue, outerEnumIntegerDefaultValue);
|
||||
}
|
||||
|
||||
private static <T> int hashCodeNullable(JsonNullable<T> a) {
|
||||
if (a == null) {
|
||||
return 1;
|
||||
}
|
||||
return a.isPresent()
|
||||
? (a.get().getClass().isArray() ? Arrays.hashCode((T[])a.get()) : Objects.hashCode(a.get()))
|
||||
: 31;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.fasterxml.jackson.annotation.JsonTypeName;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import org.openapitools.jackson.nullable.JsonNullable;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import org.openapitools.jackson.nullable.JsonNullable;
|
||||
import java.util.NoSuchElementException;
|
||||
@@ -85,12 +86,25 @@ public class HealthCheckResult {
|
||||
return false;
|
||||
}
|
||||
HealthCheckResult healthCheckResult = (HealthCheckResult) o;
|
||||
return Objects.equals(this.nullableMessage, healthCheckResult.nullableMessage);
|
||||
return equalsNullable(this.nullableMessage, healthCheckResult.nullableMessage);
|
||||
}
|
||||
|
||||
private static <T> boolean equalsNullable(JsonNullable<T> a, JsonNullable<T> b) {
|
||||
return a == b || (a != null && b != null && a.isPresent() && b.isPresent() && a.get().getClass().isArray() ? Arrays.equals((T[])a.get(), (T[])b.get()) : Objects.equals(a.get(), b.get()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(nullableMessage);
|
||||
return Objects.hash(hashCodeNullable(nullableMessage));
|
||||
}
|
||||
|
||||
private static <T> int hashCodeNullable(JsonNullable<T> a) {
|
||||
if (a == null) {
|
||||
return 1;
|
||||
}
|
||||
return a.isPresent()
|
||||
? (a.get().getClass().isArray() ? Arrays.hashCode((T[])a.get()) : Objects.hashCode(a.get()))
|
||||
: 31;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -29,6 +29,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.openapitools.jackson.nullable.JsonNullable;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import org.openapitools.jackson.nullable.JsonNullable;
|
||||
import java.util.NoSuchElementException;
|
||||
@@ -568,24 +569,37 @@ public class NullableClass extends HashMap<String, Object> {
|
||||
return false;
|
||||
}
|
||||
NullableClass nullableClass = (NullableClass) o;
|
||||
return Objects.equals(this.integerProp, nullableClass.integerProp) &&
|
||||
Objects.equals(this.numberProp, nullableClass.numberProp) &&
|
||||
Objects.equals(this.booleanProp, nullableClass.booleanProp) &&
|
||||
Objects.equals(this.stringProp, nullableClass.stringProp) &&
|
||||
Objects.equals(this.dateProp, nullableClass.dateProp) &&
|
||||
Objects.equals(this.datetimeProp, nullableClass.datetimeProp) &&
|
||||
Objects.equals(this.arrayNullableProp, nullableClass.arrayNullableProp) &&
|
||||
Objects.equals(this.arrayAndItemsNullableProp, nullableClass.arrayAndItemsNullableProp) &&
|
||||
return equalsNullable(this.integerProp, nullableClass.integerProp) &&
|
||||
equalsNullable(this.numberProp, nullableClass.numberProp) &&
|
||||
equalsNullable(this.booleanProp, nullableClass.booleanProp) &&
|
||||
equalsNullable(this.stringProp, nullableClass.stringProp) &&
|
||||
equalsNullable(this.dateProp, nullableClass.dateProp) &&
|
||||
equalsNullable(this.datetimeProp, nullableClass.datetimeProp) &&
|
||||
equalsNullable(this.arrayNullableProp, nullableClass.arrayNullableProp) &&
|
||||
equalsNullable(this.arrayAndItemsNullableProp, nullableClass.arrayAndItemsNullableProp) &&
|
||||
Objects.equals(this.arrayItemsNullable, nullableClass.arrayItemsNullable) &&
|
||||
Objects.equals(this.objectNullableProp, nullableClass.objectNullableProp) &&
|
||||
Objects.equals(this.objectAndItemsNullableProp, nullableClass.objectAndItemsNullableProp) &&
|
||||
equalsNullable(this.objectNullableProp, nullableClass.objectNullableProp) &&
|
||||
equalsNullable(this.objectAndItemsNullableProp, nullableClass.objectAndItemsNullableProp) &&
|
||||
Objects.equals(this.objectItemsNullable, nullableClass.objectItemsNullable) &&
|
||||
super.equals(o);
|
||||
}
|
||||
|
||||
private static <T> boolean equalsNullable(JsonNullable<T> a, JsonNullable<T> b) {
|
||||
return a == b || (a != null && b != null && a.isPresent() && b.isPresent() && a.get().getClass().isArray() ? Arrays.equals((T[])a.get(), (T[])b.get()) : Objects.equals(a.get(), b.get()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(integerProp, numberProp, booleanProp, stringProp, dateProp, datetimeProp, arrayNullableProp, arrayAndItemsNullableProp, arrayItemsNullable, objectNullableProp, objectAndItemsNullableProp, objectItemsNullable, super.hashCode());
|
||||
return Objects.hash(hashCodeNullable(integerProp), hashCodeNullable(numberProp), hashCodeNullable(booleanProp), hashCodeNullable(stringProp), hashCodeNullable(dateProp), hashCodeNullable(datetimeProp), hashCodeNullable(arrayNullableProp), hashCodeNullable(arrayAndItemsNullableProp), arrayItemsNullable, hashCodeNullable(objectNullableProp), hashCodeNullable(objectAndItemsNullableProp), objectItemsNullable, super.hashCode());
|
||||
}
|
||||
|
||||
private static <T> int hashCodeNullable(JsonNullable<T> a) {
|
||||
if (a == null) {
|
||||
return 1;
|
||||
}
|
||||
return a.isPresent()
|
||||
? (a.get().getClass().isArray() ? Arrays.hashCode((T[])a.get()) : Objects.hashCode(a.get()))
|
||||
: 31;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user