Package net.sf.json

Class AbstractJSON

  • All Implemented Interfaces:
    java.io.Serializable, JSON
    Direct Known Subclasses:
    JSONArray, JSONObject

    abstract class AbstractJSON
    extends java.lang.Object
    implements JSON
    Base class for JSONObject and JSONArray.
    • Constructor Detail

      • AbstractJSON

        AbstractJSON()
    • Method Detail

      • addInstance

        protected static boolean addInstance​(java.lang.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,
                                                    java.lang.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​(java.lang.String key,
                                                   java.lang.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​(java.lang.String warning,
                                            JsonConfig jsonConfig)
        Fires a warning event.
        Parameters:
        warning - the warning message
      • removeInstance

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

        protected java.lang.Object _processValue​(java.lang.Object value,
                                                 JsonConfig jsonConfig)
      • getCycleSet

        private static java.util.Set getCycleSet()
      • write

        public final java.io.Writer write​(java.io.Writer writer)
                                   throws java.io.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:
        java.io.IOException
      • writeCanonical

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

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