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

com.eg.google.gson.JsonElement Maven / Gradle / Ivy

There is a newer version: 2.1.3
Show newest version
package com.eg.google.gson;

import com.eg.google.gson.internal.Streams;
import com.eg.google.gson.stream.JsonWriter;

import java.io.IOException;
import java.io.StringWriter;
import java.math.BigDecimal;
import java.math.BigInteger;


public abstract class JsonElement
{
  abstract JsonElement deepCopy();

  public boolean isJsonArray() {
    return this instanceof JsonArray;
  }





  public boolean isJsonObject()
  {
   return this instanceof JsonObject;
  }





  public boolean isJsonPrimitive()
  {
     return this instanceof JsonPrimitive;
  }






  public boolean isJsonNull()
  {
     return this instanceof JsonNull;
  }









  public JsonObject getAsJsonObject()
  {
     if (isJsonObject()) {
       return (JsonObject) this;
     }
     throw new IllegalStateException("Not a JSON Object: " + this);
  }









  public JsonArray getAsJsonArray() {
    if (isJsonArray()) {
      return (JsonArray) this;
    }
    throw new IllegalStateException("This is not a JSON Array.");
  }









  public JsonPrimitive getAsJsonPrimitive() {
    if (isJsonPrimitive()) {
      return (JsonPrimitive) this;
    }
    throw new IllegalStateException("This is not a JSON Primitive.");
  }










  public JsonNull getAsJsonNull() {
    if (isJsonNull()) {
      return (JsonNull) this;
    }
    throw new IllegalStateException("This is not a JSON Null.");
  }









  public boolean getAsBoolean() {
    throw new UnsupportedOperationException(getClass().getSimpleName());
  }









  Boolean getAsBooleanWrapper() {
    throw new UnsupportedOperationException(getClass().getSimpleName());
  }









  public Number getAsNumber() {
    throw new UnsupportedOperationException(getClass().getSimpleName());
  }









  public String getAsString() {
    throw new UnsupportedOperationException(getClass().getSimpleName());
  }









  public double getAsDouble() {
    throw new UnsupportedOperationException(getClass().getSimpleName());
  }









  public float getAsFloat()
  {
/* 217 */     throw new UnsupportedOperationException(getClass().getSimpleName());
  }









  public long getAsLong() {
      throw new UnsupportedOperationException(getClass().getSimpleName());
  }









  public int getAsInt() {
    throw new UnsupportedOperationException(getClass().getSimpleName());
  }










  public byte getAsByte() {
      throw new UnsupportedOperationException(getClass().getSimpleName());
  }










  public char getAsCharacter() {
    throw new UnsupportedOperationException(getClass().getSimpleName());
  }










  public BigDecimal getAsBigDecimal() {
    throw new UnsupportedOperationException(getClass().getSimpleName());
  }










  public BigInteger getAsBigInteger() {
      throw new UnsupportedOperationException(getClass().getSimpleName());
  }









  public short getAsShort() {
      throw new UnsupportedOperationException(getClass().getSimpleName());
  }



  public String toString()
  {
    try {
      StringWriter stringWriter = new StringWriter();
      JsonWriter jsonWriter = new JsonWriter(stringWriter);
      jsonWriter.setLenient(true);
      Streams.write(this, jsonWriter);
      return stringWriter.toString();
    } catch (IOException e) {
      throw new AssertionError(e);
    }
  }
}






© 2015 - 2024 Weber Informatics LLC | Privacy Policy