Class JsonContent

java.lang.Object
org.apache.velocity.tools.generic.JsonContent

public class JsonContent extends Object
Container for *either* an array *or* an object
  • Constructor Details

    • JsonContent

      public JsonContent(org.json.simple.JsonObject object)
      wraps an object
      Parameters:
      object - JsonObject to wrap
    • JsonContent

      public JsonContent(org.json.simple.JsonArray array)
      wraps an array
      Parameters:
      array - JsonArray to wrap
  • Method Details

    • get

      public Object get(int index)
      Get a value from root array
      Parameters:
      index - array index
      Returns:
      value, or null
    • get

      public Object get(String key)
      Get a property from root object
      Parameters:
      key - map key
      Returns:
      property value, or null
    • keys

      public Iterator<String> keys()
      Iterate keys of root object.
      Returns:
      iterator
    • keySet

      public Set<String> keySet()
      Get set of root object keys.
      Returns:
      keys set
    • iterator

      public Iterator iterator()
      Get an iterator. For a root object, returns an iterator over key names. For a root array, returns an iterator over contained objects.
      Returns:
      iterator
    • size

      public int size()
      Get size of root object or array.
      Returns:
      size
    • toString

      public String toString()
      Convert JSON object or array into string
      Overrides:
      toString in class Object
      Returns:
      JSON representation of the root object or array
    • isNull

      public boolean isNull()
      Check if wrapped object is null
      Returns:
      true if wrapped object is null
    • isObject

      public boolean isObject()
      Check if wrapped object is a JsonObject
      Returns:
      true if wrapped object is a JsonObject
    • isArray

      public boolean isArray()
      Check if wrapped object is a JsonArray
      Returns:
      true if wrapped object is a JsonArray
    • getObject

      public org.json.simple.JsonObject getObject()
      Gives access to the wrapped JsonObject, if any
      Returns:
      JsonObject or null
    • getArray

      public org.json.simple.JsonArray getArray()
      Gives acces to the wrapped JsonArray, if any
      Returns:
      JsonArray or null