Class Jval

java.lang.Object
arc.util.serialization.Jval

public class Jval extends Object
An hsjon parser. Can be used as a standard json value. Output can be converted to standard JSON. This class is heavily based upon the Hjson Java implementation.
  • Field Details

    • TRUE

      public static final Jval TRUE
    • FALSE

      public static final Jval FALSE
    • NULL

      public static final Jval NULL
  • Method Details

    • newObject

      public static Jval newObject()
    • newArray

      public static Jval newArray()
    • read

      public static Jval read(Reader reader)
      Reads a Hjson value from the given reader.

      Characters are read in chunks and buffered internally, therefore wrapping an existing reader in an additional BufferedReader does not improve reading performance.

      Parameters:
      reader - the reader to read the Hjson value from
      Returns:
      the Hjson value that has been read
    • read

      public static Jval read(byte[] bytes)
    • read

      public static Jval read(String text)
      Reads a Hjson value from the given string.
      Parameters:
      text - the string that contains the Hjson value
      Returns:
      the Hjson value that has been read
    • getType

      public Jval.Jtype getType()
    • valueOf

      public static Jval valueOf(int value)
    • valueOf

      public static Jval valueOf(long value)
    • valueOf

      public static Jval valueOf(float value)
    • valueOf

      public static Jval valueOf(double value)
    • valueOf

      public static Jval valueOf(String string)
    • valueOf

      public static Jval valueOf(boolean value)
    • isObject

      public boolean isObject()
    • isArray

      public boolean isArray()
    • isNumber

      public boolean isNumber()
    • isString

      public boolean isString()
    • isBoolean

      public boolean isBoolean()
    • isTrue

      public boolean isTrue()
    • isFalse

      public boolean isFalse()
    • isNull

      public boolean isNull()
    • asObject

      public Jval.JsonMap asObject()
    • asArray

      public Jval.JsonArray asArray()
    • asInt

      public int asInt()
    • asLong

      public long asLong()
    • asFloat

      public float asFloat()
    • asDouble

      public double asDouble()
    • asString

      public String asString()
    • asBool

      public boolean asBool()
    • asNumber

      public Number asNumber()
    • get

      public Jval get(String name)
    • add

      public void add(String name, Jval val)
    • add

      public void add(String name, String val)
    • add

      public Jval add(Jval value)
    • add

      public Jval add(String value)
    • add

      public Jval add(Number value)
    • add

      public Jval add(boolean value)
    • put

      public Jval put(String name, Jval val)
    • put

      public Jval put(String name, String val)
    • put

      public Jval put(String name, Number val)
    • put

      public Jval put(String name, boolean val)
    • remove

      public Jval remove(String name)
    • has

      public boolean has(String name)
    • getInt

      public int getInt(String name, int defaultValue)
    • getLong

      public long getLong(String name, long defaultValue)
    • getFloat

      public float getFloat(String name, float defaultValue)
    • getDouble

      public double getDouble(String name, double defaultValue)
    • getBool

      public boolean getBool(String name, boolean defaultValue)
    • getString

      @Nullable public String getString(String name)
    • getString

      public String getString(String name, String defaultValue)
    • 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.

      Parameters:
      writer - the writer to write this value to
      Throws:
      IOException - if an I/O error occurs in the writer
    • writeTo

      public void writeTo(Writer writer, Jval.Jformat format) throws IOException
      Writes the JSON/Hjson representation of this value to the given writer using the given formatting.

      Writing performance can be improved by using a BufferedWriter.

      Parameters:
      writer - the writer to write this value to
      format - controls the formatting
      Throws:
      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.
      Overrides:
      toString in class Object
    • toString

      public String toString(Jval.Jformat format)
      Returns the JSON/Hjson string for this value using the given formatting.
      Parameters:
      format - controls the formatting
      Returns:
      a JSON/Hjson string that represents this value
    • equals

      public boolean equals(Object object)
      Overrides:
      equals in class Object