Package net.sf.json

Class AbstractJSON

java.lang.Object
net.sf.json.AbstractJSON
All Implemented Interfaces:
Serializable, JSON
Direct Known Subclasses:
JSONArray, JSONObject

abstract class AbstractJSON extends Object implements JSON
Base class for JSONObject and JSONArray.
  • Field Details

  • Constructor Details

    • AbstractJSON

      AbstractJSON()
  • Method Details

    • addInstance

      protected static boolean addInstance(Object instance)
      Adds a reference for cycle detection check.
      Parameters:
      instance - the reference to add
      Returns:
      true if the instance has not been added previously, false otherwise.
    • fireArrayEndEvent

      protected static void fireArrayEndEvent(JsonConfig jsonConfig)
      Fires an end of array event.
    • fireArrayStartEvent

      protected static void fireArrayStartEvent(JsonConfig jsonConfig)
      Fires a start of array event.
    • fireElementAddedEvent

      protected static void fireElementAddedEvent(int index, Object element, JsonConfig jsonConfig)
      Fires an element added event.
      Parameters:
      index - the index where the element was added
      element - the added element
    • fireErrorEvent

      protected static void fireErrorEvent(JSONException jsone, JsonConfig jsonConfig)
      Fires an error event.
      Parameters:
      jsone - the thrown exception
    • fireObjectEndEvent

      protected static void fireObjectEndEvent(JsonConfig jsonConfig)
      Fires an end of object event.
    • fireObjectStartEvent

      protected static void fireObjectStartEvent(JsonConfig jsonConfig)
      Fires a start of object event.
    • firePropertySetEvent

      protected static void firePropertySetEvent(String key, Object value, boolean accumulated, JsonConfig jsonConfig)
      Fires a property set event.
      Parameters:
      key - the name of the property
      value - the value of the property
      accumulated - if the value has been accumulated over 'key'
    • fireWarnEvent

      protected static void fireWarnEvent(String warning, JsonConfig jsonConfig)
      Fires a warning event.
      Parameters:
      warning - the warning message
    • removeInstance

      protected static void removeInstance(Object instance)
      Removes a reference for cycle detection check.
    • _processValue

      protected Object _processValue(Object value, JsonConfig jsonConfig)
    • getCycleSet

      private static Set getCycleSet()
    • write

      public final Writer write(Writer writer) throws IOException
      Description copied from interface: JSON
      Write the contents as JSON text to a writer. For compactness, no whitespace is added.

      Warning: This method assumes that the data structure is acyclical.

      Specified by:
      write in interface JSON
      Returns:
      The writer.
      Throws:
      IOException
    • writeCanonical

      public final Writer writeCanonical(Writer writer) throws IOException
      Description copied from interface: JSON
      Writes the canonicalized form of this JSON object.
      Specified by:
      writeCanonical in interface JSON
      Throws:
      IOException
    • write

      protected abstract void write(Writer w, AbstractJSON.WritingVisitor v) throws IOException
      Throws:
      IOException