All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.finbourne.luminesce.model.ErrorHighlightResponse Maven / Gradle / Ivy

/*
 * FINBOURNE Luminesce Web API
 *
 * 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 com.finbourne.luminesce.model;

import java.util.Objects;
import com.finbourne.luminesce.model.ErrorHighlightItem;
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.ArrayList;
import java.util.Arrays;
import java.util.List;

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 com.finbourne.luminesce.JSON;

/**
 * Response for error highlighting
 */
@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen")
public class ErrorHighlightResponse {
  public static final String SERIALIZED_NAME_ERRORS = "errors";
  @SerializedName(SERIALIZED_NAME_ERRORS)
  private List errors = new ArrayList<>();

  public static final String SERIALIZED_NAME_SQL_WITH_MARKER = "sqlWithMarker";
  @SerializedName(SERIALIZED_NAME_SQL_WITH_MARKER)
  private String sqlWithMarker;

  public ErrorHighlightResponse() {
  }

  public ErrorHighlightResponse errors(List errors) {
    
    this.errors = errors;
    return this;
  }

  public ErrorHighlightResponse addErrorsItem(ErrorHighlightItem errorsItem) {
    if (this.errors == null) {
      this.errors = new ArrayList<>();
    }
    this.errors.add(errorsItem);
    return this;
  }

   /**
   * The errors within the Sql
   * @return errors
  **/
  @jakarta.annotation.Nonnull
  public List getErrors() {
    return errors;
  }


  public void setErrors(List errors) {
    this.errors = errors;
  }


  public ErrorHighlightResponse sqlWithMarker(String sqlWithMarker) {
    
    this.sqlWithMarker = sqlWithMarker;
    return this;
  }

   /**
   * The SQL this is for, with characters indicating the error locations
   * @return sqlWithMarker
  **/
  @jakarta.annotation.Nonnull
  public String getSqlWithMarker() {
    return sqlWithMarker;
  }


  public void setSqlWithMarker(String sqlWithMarker) {
    this.sqlWithMarker = sqlWithMarker;
  }



  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }
    ErrorHighlightResponse errorHighlightResponse = (ErrorHighlightResponse) o;
    return Objects.equals(this.errors, errorHighlightResponse.errors) &&
        Objects.equals(this.sqlWithMarker, errorHighlightResponse.sqlWithMarker);
  }

  @Override
  public int hashCode() {
    return Objects.hash(errors, sqlWithMarker);
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("class ErrorHighlightResponse {\n");
    sb.append("    errors: ").append(toIndentedString(errors)).append("\n");
    sb.append("    sqlWithMarker: ").append(toIndentedString(sqlWithMarker)).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("errors");
    openapiFields.add("sqlWithMarker");

    // a set of required properties/fields (JSON key names)
    openapiRequiredFields = new HashSet();
    openapiRequiredFields.add("errors");
    openapiRequiredFields.add("sqlWithMarker");
  }

 /**
  * 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 ErrorHighlightResponse
  */
  public static void validateJsonElement(JsonElement jsonElement) throws IOException {
      if (jsonElement == null) {
        if (!ErrorHighlightResponse.openapiRequiredFields.isEmpty()) { // has required fields but JSON element is null
          throw new IllegalArgumentException(String.format("The required field(s) %s in ErrorHighlightResponse is not found in the empty JSON string", ErrorHighlightResponse.openapiRequiredFields.toString()));
        }
      }

      // check to make sure all required properties/fields are present in the JSON string
      for (String requiredField : ErrorHighlightResponse.openapiRequiredFields) {
        if (jsonElement.getAsJsonObject().get(requiredField) == null) {
          throw new IllegalArgumentException(String.format("The required field `%s` is not found in the JSON string: %s", requiredField, jsonElement.toString()));
        }
      }
        JsonObject jsonObj = jsonElement.getAsJsonObject();
      // ensure the json data is an array
      if (!jsonObj.get("errors").isJsonArray()) {
        throw new IllegalArgumentException(String.format("Expected the field `errors` to be an array in the JSON string but got `%s`", jsonObj.get("errors").toString()));
      }

      JsonArray jsonArrayerrors = jsonObj.getAsJsonArray("errors");
      // validate the required field `errors` (array)
      for (int i = 0; i < jsonArrayerrors.size(); i++) {
        ErrorHighlightItem.validateJsonElement(jsonArrayerrors.get(i));
      };
      if (!jsonObj.get("sqlWithMarker").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `sqlWithMarker` to be a primitive type in the JSON string but got `%s`", jsonObj.get("sqlWithMarker").toString()));
      }
  }

  public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
    @SuppressWarnings("unchecked")
    @Override
    public  TypeAdapter create(Gson gson, TypeToken type) {
       if (!ErrorHighlightResponse.class.isAssignableFrom(type.getRawType())) {
         return null; // this class only serializes 'ErrorHighlightResponse' and its subtypes
       }
       final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class);
       final TypeAdapter thisAdapter
                        = gson.getDelegateAdapter(this, TypeToken.get(ErrorHighlightResponse.class));

       return (TypeAdapter) new TypeAdapter() {
           @Override
           public void write(JsonWriter out, ErrorHighlightResponse value) throws IOException {
             JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
             elementAdapter.write(out, obj);
           }

           @Override
           public ErrorHighlightResponse read(JsonReader in) throws IOException {
             JsonElement jsonElement = elementAdapter.read(in);
             validateJsonElement(jsonElement);
             return thisAdapter.fromJsonTree(jsonElement);
           }

       }.nullSafe();
    }
  }

 /**
  * Create an instance of ErrorHighlightResponse given an JSON string
  *
  * @param jsonString JSON string
  * @return An instance of ErrorHighlightResponse
  * @throws IOException if the JSON string is invalid with respect to ErrorHighlightResponse
  */
  public static ErrorHighlightResponse fromJson(String jsonString) throws IOException {
    return JSON.getGson().fromJson(jsonString, ErrorHighlightResponse.class);
  }

 /**
  * Convert an instance of ErrorHighlightResponse to an JSON string
  *
  * @return JSON string
  */
  public String toJson() {
    return JSON.getGson().toJson(this);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy