Klasse JsonValue

java.lang.Object
com.restfb.json.JsonValue
Alle implementierten Schnittstellen:
Serializable
Bekannte direkte Unterklassen:
JsonArray, JsonObject

public abstract class JsonValue extends Object implements Serializable
Represents a JSON value. This can be a JSON object, an array, a number, a string, or one of the literals true, false, and null.

The literals true, false, and null are represented by the constants Json.TRUE, Json.FALSE, and Json.NULL.

JSON objects and arrays are represented by the subtypes JsonObject and JsonArray. Instances of these types can be created using the public constructors of these classes.

Instances that represent JSON numbers, strings and boolean values can be created using the static factory methods Json.value(String), Json.value(long), Json.value(double), etc.

In order to find out whether an instance of this class is of a certain type, the methods isObject(), isArray(), isString(), isNumber() etc. can be used.

If the type of a JSON value is known, the methods asObject(), asArray(), asString(), asInt(), etc. can be used to get this value directly in the appropriate target type.

This class is not supposed to be extended by clients.

Siehe auch:
  • Feldübersicht

    Felder
    Modifizierer und Typ
    Feld
    Beschreibung
    protected static final String
     
    protected static final String
     
    protected static final String
     
    protected static final String
     
    protected static final String
     
  • Methodenübersicht

    Modifizierer und Typ
    Methode
    Beschreibung
    Returns this JSON value as JsonArray, assuming that this value represents a JSON array.
    boolean
    Returns this JSON value as a boolean value, assuming that this value is either true or false.
    double
    Returns this JSON value as a double value, assuming that this value represents a JSON number.
    float
    Returns this JSON value as a float value, assuming that this value represents a JSON number.
    int
    Returns this JSON value as an int value, assuming that this value represents a JSON number that can be interpreted as Java int.
    long
    Returns this JSON value as a long value, assuming that this value represents a JSON number that can be interpreted as Java long.
    Returns this JSON value as JsonObject, assuming that this value represents a JSON object.
    Returns this JSON value as String, assuming that this value represents a JSON string.
    boolean
    equals(Object object)
    Indicates whether some other object is "equal to" this one according to the contract specified in Object.equals(Object).
    int
     
    boolean
    Detects whether this value represents a JSON array.
    boolean
    Detects whether this value represents a boolean value.
    boolean
    Detects whether this value represents the JSON literal false.
    boolean
    Detects whether this value represents the JSON literal null.
    boolean
    Detects whether this value represents a JSON number.
    boolean
    Detects whether this value represents a JSON object.
    boolean
    Detects whether this value represents a JSON string.
    boolean
    Detects whether this value represents the JSON literal true.
    Returns the JSON string for this value in its minimal form, without any additional whitespace.
    Returns the JSON string for this value using the given formatting.
    void
    writeTo(Writer writer)
    Writes the JSON representation of this value to the given writer in its minimal form, without any additional whitespace.
    void
    writeTo(Writer writer, WriterConfig config)
    Writes the JSON representation of this value to the given writer using the given formatting.

    Von Klasse geerbte Methoden java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Felddetails

  • Methodendetails

    • isObject

      public boolean isObject()
      Detects whether this value represents a JSON object. If this is the case, this value is an instance of JsonObject.
      Gibt zurück:
      true if this value is an instance of JsonObject
    • isArray

      public boolean isArray()
      Detects whether this value represents a JSON array. If this is the case, this value is an instance of JsonArray.
      Gibt zurück:
      true if this value is an instance of JsonArray
    • isNumber

      public boolean isNumber()
      Detects whether this value represents a JSON number.
      Gibt zurück:
      true if this value represents a JSON number
    • isString

      public boolean isString()
      Detects whether this value represents a JSON string.
      Gibt zurück:
      true if this value represents a JSON string
    • isBoolean

      public boolean isBoolean()
      Detects whether this value represents a boolean value.
      Gibt zurück:
      true if this value represents either the JSON literal true or false
    • isTrue

      public boolean isTrue()
      Detects whether this value represents the JSON literal true.
      Gibt zurück:
      true if this value represents the JSON literal true
    • isFalse

      public boolean isFalse()
      Detects whether this value represents the JSON literal false.
      Gibt zurück:
      true if this value represents the JSON literal false
    • isNull

      public boolean isNull()
      Detects whether this value represents the JSON literal null.
      Gibt zurück:
      true if this value represents the JSON literal null
    • asObject

      public JsonObject asObject()
      Returns this JSON value as JsonObject, assuming that this value represents a JSON object. If this is not the case, an exception is thrown.
      Gibt zurück:
      a JSONObject for this value
      Löst aus:
      UnsupportedOperationException - if this value is not a JSON object
    • asArray

      public JsonArray asArray()
      Returns this JSON value as JsonArray, assuming that this value represents a JSON array. If this is not the case, an exception is thrown.
      Gibt zurück:
      a JSONArray for this value
      Löst aus:
      UnsupportedOperationException - if this value is not a JSON array
    • asInt

      public int asInt()
      Returns this JSON value as an int value, assuming that this value represents a JSON number that can be interpreted as Java int. If this is not the case, an exception is thrown.

      To be interpreted as Java int, the JSON number must neither contain an exponent nor a fraction part. Moreover, the number must be in the Integer range.

      Gibt zurück:
      this value as int
      Löst aus:
      UnsupportedOperationException - if this value is not a JSON number
      NumberFormatException - if this JSON number can not be interpreted as int value
    • asLong

      public long asLong()
      Returns this JSON value as a long value, assuming that this value represents a JSON number that can be interpreted as Java long. If this is not the case, an exception is thrown.

      To be interpreted as Java long, the JSON number must neither contain an exponent nor a fraction part. Moreover, the number must be in the Long range.

      Gibt zurück:
      this value as long
      Löst aus:
      UnsupportedOperationException - if this value is not a JSON number
      NumberFormatException - if this JSON number can not be interpreted as long value
    • asFloat

      public float asFloat()
      Returns this JSON value as a float value, assuming that this value represents a JSON number. If this is not the case, an exception is thrown.

      If the JSON number is out of the Float range, Float.POSITIVE_INFINITY or Float.NEGATIVE_INFINITY is returned.

      Gibt zurück:
      this value as float
      Löst aus:
      UnsupportedOperationException - if this value is not a JSON number
    • asDouble

      public double asDouble()
      Returns this JSON value as a double value, assuming that this value represents a JSON number. If this is not the case, an exception is thrown.

      If the JSON number is out of the Double range, Double.POSITIVE_INFINITY or Double.NEGATIVE_INFINITY is returned.

      Gibt zurück:
      this value as double
      Löst aus:
      UnsupportedOperationException - if this value is not a JSON number
    • asString

      public String asString()
      Returns this JSON value as String, assuming that this value represents a JSON string. If this is not the case, an exception is thrown.
      Gibt zurück:
      the string represented by this value
      Löst aus:
      UnsupportedOperationException - if this value is not a JSON string
    • asBoolean

      public boolean asBoolean()
      Returns this JSON value as a boolean value, assuming that this value is either true or false. If this is not the case, an exception is thrown.
      Gibt zurück:
      this value as boolean
      Löst aus:
      UnsupportedOperationException - if this value is neither true or false
    • writeTo

      public void writeTo(Writer writer) throws IOException
      Writes the JSON representation of this value to the given writer in its minimal form, without any additional whitespace.

      Writing performance can be improved by using a BufferedWriter.

      Parameter:
      writer - the writer to write this value to
      Löst aus:
      IOException - if an I/O error occurs in the writer
    • writeTo

      public void writeTo(Writer writer, WriterConfig config) throws IOException
      Writes the JSON representation of this value to the given writer using the given formatting.

      Writing performance can be improved by using a BufferedWriter.

      Parameter:
      writer - the writer to write this value to
      config - a configuration that controls the formatting or null for the minimal form
      Löst aus:
      IOException - if an I/O error occurs in the writer
    • toString

      public String toString()
      Returns the JSON string for this value in its minimal form, without any additional whitespace. The result is guaranteed to be a valid input for the method Json.parse(String) and to create a value that is equal to this object.
      Setzt außer Kraft:
      toString in Klasse Object
      Gibt zurück:
      a JSON string that represents this value
    • toString

      public String toString(WriterConfig config)
      Returns the JSON string for this value using the given formatting.
      Parameter:
      config - a configuration that controls the formatting or null for the minimal form
      Gibt zurück:
      a JSON string that represents this value
    • equals

      public boolean equals(Object object)
      Indicates whether some other object is "equal to" this one according to the contract specified in Object.equals(Object).

      Two JsonValues are considered equal if and only if they represent the same JSON text. As a consequence, two given JsonObjects may be different even though they contain the same set of names with the same values, but in a different order.

      Setzt außer Kraft:
      equals in Klasse Object
      Parameter:
      object - the reference object with which to compare
      Gibt zurück:
      true if this object is the same as the object argument; false otherwise
    • hashCode

      public int hashCode()
      Setzt außer Kraft:
      hashCode in Klasse Object