[Java][jersey2] Make (de)serialization work for oneOf models, add convenience and comparison methods (#6323)

This commit is contained in:
Slavek Kabrda
2020-05-25 09:17:52 +02:00
committed by GitHub
parent 202d184ce2
commit 205514c455
4 changed files with 179 additions and 0 deletions

View File

@@ -14,10 +14,13 @@
package org.openapitools.client.model;
import org.openapitools.client.ApiException;
import java.util.Objects;
import java.lang.reflect.Type;
import java.util.Map;
import javax.ws.rs.core.GenericType;
import com.fasterxml.jackson.annotation.JsonValue;
/**
* Abstract class for oneOf,anyOf schemas defined in OpenAPI spec
*/
@@ -50,6 +53,7 @@ public abstract class AbstractOpenApiSchema {
*
* @return an instance of the actual schema/object
*/
@JsonValue
public Object getActualInstance() {return instance;}
/***
@@ -68,6 +72,46 @@ public abstract class AbstractOpenApiSchema {
return schemaType;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class ").append(getClass()).append(" {\n");
sb.append(" instance: ").append(toIndentedString(instance)).append("\n");
sb.append(" isNullable: ").append(toIndentedString(isNullable)).append("\n");
sb.append(" schemaType: ").append(toIndentedString(schemaType)).append("\n");
sb.append("}");
return sb.toString();
}
/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(java.lang.Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
AbstractOpenApiSchema a = (AbstractOpenApiSchema) o;
return Objects.equals(this.instance, a.instance) &&
Objects.equals(this.isNullable, a.isNullable) &&
Objects.equals(this.schemaType, a.schemaType);
}
@Override
public int hashCode() {
return Objects.hash(instance, isNullable, schemaType);
}
/***
* Is nullalble
*