software.tnb.jira.validation.generated.model.IncludedFields Maven / Gradle / Ivy
The newest version!
/*
* The Jira Cloud platform REST API
* Jira Cloud platform REST API documentation
*
* The version of the OpenAPI document: 1001.0.0-SNAPSHOT
* Contact: [email protected]
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
package software.tnb.jira.validation.generated.model;
import java.util.Objects;
import com.google.gson.TypeAdapter;
import com.google.gson.annotations.JsonAdapter;
import com.google.gson.annotations.SerializedName;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.Set;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.reflect.TypeToken;
import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import software.tnb.jira.validation.generated.JSON;
/**
* IncludedFields
*/
@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2023-11-09T10:37:50.591249290Z[Etc/UTC]")
public class IncludedFields {
public static final String SERIALIZED_NAME_EXCLUDED = "excluded";
@SerializedName(SERIALIZED_NAME_EXCLUDED)
private Set excluded;
public static final String SERIALIZED_NAME_ACTUALLY_INCLUDED = "actuallyIncluded";
@SerializedName(SERIALIZED_NAME_ACTUALLY_INCLUDED)
private Set actuallyIncluded;
public static final String SERIALIZED_NAME_INCLUDED = "included";
@SerializedName(SERIALIZED_NAME_INCLUDED)
private Set included;
public IncludedFields() {
}
public IncludedFields excluded(Set excluded) {
this.excluded = excluded;
return this;
}
public IncludedFields addExcludedItem(String excludedItem) {
if (this.excluded == null) {
this.excluded = new LinkedHashSet<>();
}
this.excluded.add(excludedItem);
return this;
}
/**
* Get excluded
* @return excluded
**/
@jakarta.annotation.Nullable
public Set getExcluded() {
return excluded;
}
public void setExcluded(Set excluded) {
this.excluded = excluded;
}
public IncludedFields actuallyIncluded(Set actuallyIncluded) {
this.actuallyIncluded = actuallyIncluded;
return this;
}
public IncludedFields addActuallyIncludedItem(String actuallyIncludedItem) {
if (this.actuallyIncluded == null) {
this.actuallyIncluded = new LinkedHashSet<>();
}
this.actuallyIncluded.add(actuallyIncludedItem);
return this;
}
/**
* Get actuallyIncluded
* @return actuallyIncluded
**/
@jakarta.annotation.Nullable
public Set getActuallyIncluded() {
return actuallyIncluded;
}
public void setActuallyIncluded(Set actuallyIncluded) {
this.actuallyIncluded = actuallyIncluded;
}
public IncludedFields included(Set included) {
this.included = included;
return this;
}
public IncludedFields addIncludedItem(String includedItem) {
if (this.included == null) {
this.included = new LinkedHashSet<>();
}
this.included.add(includedItem);
return this;
}
/**
* Get included
* @return included
**/
@jakarta.annotation.Nullable
public Set getIncluded() {
return included;
}
public void setIncluded(Set included) {
this.included = included;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
IncludedFields includedFields = (IncludedFields) o;
return Objects.equals(this.excluded, includedFields.excluded) &&
Objects.equals(this.actuallyIncluded, includedFields.actuallyIncluded) &&
Objects.equals(this.included, includedFields.included);
}
@Override
public int hashCode() {
return Objects.hash(excluded, actuallyIncluded, included);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class IncludedFields {\n");
sb.append(" excluded: ").append(toIndentedString(excluded)).append("\n");
sb.append(" actuallyIncluded: ").append(toIndentedString(actuallyIncluded)).append("\n");
sb.append(" included: ").append(toIndentedString(included)).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(Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}
public static HashSet openapiFields;
public static HashSet openapiRequiredFields;
static {
// a set of all properties/fields (JSON key names)
openapiFields = new HashSet();
openapiFields.add("excluded");
openapiFields.add("actuallyIncluded");
openapiFields.add("included");
// a set of required properties/fields (JSON key names)
openapiRequiredFields = new HashSet();
}
/**
* Validates the JSON Element and throws an exception if issues found
*
* @param jsonElement JSON Element
* @throws IOException if the JSON Element is invalid with respect to IncludedFields
*/
public static void validateJsonElement(JsonElement jsonElement) throws IOException {
if (jsonElement == null) {
if (!IncludedFields.openapiRequiredFields.isEmpty()) { // has required fields but JSON element is null
throw new IllegalArgumentException(String.format("The required field(s) %s in IncludedFields is not found in the empty JSON string", IncludedFields.openapiRequiredFields.toString()));
}
}
Set> entries = jsonElement.getAsJsonObject().entrySet();
// check to see if the JSON string contains additional fields
for (Entry entry : entries) {
if (!IncludedFields.openapiFields.contains(entry.getKey())) {
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `IncludedFields` properties. JSON: %s", entry.getKey(), jsonElement.toString()));
}
}
JsonObject jsonObj = jsonElement.getAsJsonObject();
// ensure the optional json data is an array if present
if (jsonObj.get("excluded") != null && !jsonObj.get("excluded").isJsonNull() && !jsonObj.get("excluded").isJsonArray()) {
throw new IllegalArgumentException(String.format("Expected the field `excluded` to be an array in the JSON string but got `%s`", jsonObj.get("excluded").toString()));
}
// ensure the optional json data is an array if present
if (jsonObj.get("actuallyIncluded") != null && !jsonObj.get("actuallyIncluded").isJsonNull() && !jsonObj.get("actuallyIncluded").isJsonArray()) {
throw new IllegalArgumentException(String.format("Expected the field `actuallyIncluded` to be an array in the JSON string but got `%s`", jsonObj.get("actuallyIncluded").toString()));
}
// ensure the optional json data is an array if present
if (jsonObj.get("included") != null && !jsonObj.get("included").isJsonNull() && !jsonObj.get("included").isJsonArray()) {
throw new IllegalArgumentException(String.format("Expected the field `included` to be an array in the JSON string but got `%s`", jsonObj.get("included").toString()));
}
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public TypeAdapter create(Gson gson, TypeToken type) {
if (!IncludedFields.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'IncludedFields' and its subtypes
}
final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(IncludedFields.class));
return (TypeAdapter) new TypeAdapter() {
@Override
public void write(JsonWriter out, IncludedFields value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
elementAdapter.write(out, obj);
}
@Override
public IncludedFields read(JsonReader in) throws IOException {
JsonElement jsonElement = elementAdapter.read(in);
validateJsonElement(jsonElement);
return thisAdapter.fromJsonTree(jsonElement);
}
}.nullSafe();
}
}
/**
* Create an instance of IncludedFields given an JSON string
*
* @param jsonString JSON string
* @return An instance of IncludedFields
* @throws IOException if the JSON string is invalid with respect to IncludedFields
*/
public static IncludedFields fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, IncludedFields.class);
}
/**
* Convert an instance of IncludedFields to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}