Package net.sf.json
Class AbstractJSON
- java.lang.Object
-
- net.sf.json.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
AbstractJSON.CycleSet
(package private) static interface
AbstractJSON.WritingVisitor
-
Field Summary
Fields Modifier and Type Field Description private static AbstractJSON.WritingVisitor
CANONICAL
private static AbstractJSON.CycleSet
cycleSet
private static org.apache.commons.logging.Log
log
private static AbstractJSON.WritingVisitor
NORMAL
-
Constructor Summary
Constructors Constructor Description AbstractJSON()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected java.lang.Object
_processValue(java.lang.Object value, JsonConfig jsonConfig)
protected static boolean
addInstance(java.lang.Object instance)
Adds a reference for cycle detection check.protected static void
fireArrayEndEvent(JsonConfig jsonConfig)
Fires an end of array event.protected static void
fireArrayStartEvent(JsonConfig jsonConfig)
Fires a start of array event.protected static void
fireElementAddedEvent(int index, java.lang.Object element, JsonConfig jsonConfig)
Fires an element added event.protected static void
fireErrorEvent(JSONException jsone, JsonConfig jsonConfig)
Fires an error event.protected static void
fireObjectEndEvent(JsonConfig jsonConfig)
Fires an end of object event.protected static void
fireObjectStartEvent(JsonConfig jsonConfig)
Fires a start of object event.protected static void
firePropertySetEvent(java.lang.String key, java.lang.Object value, boolean accumulated, JsonConfig jsonConfig)
Fires a property set event.protected static void
fireWarnEvent(java.lang.String warning, JsonConfig jsonConfig)
Fires a warning event.private static java.util.Set
getCycleSet()
protected static void
removeInstance(java.lang.Object instance)
Removes a reference for cycle detection check.java.io.Writer
write(java.io.Writer writer)
Write the contents as JSON text to a writer.protected abstract void
write(java.io.Writer w, AbstractJSON.WritingVisitor v)
java.io.Writer
writeCanonical(java.io.Writer writer)
Writes the canonicalized form of this JSON object.
-
-
-
Field Detail
-
cycleSet
private static AbstractJSON.CycleSet cycleSet
-
log
private static final org.apache.commons.logging.Log log
-
NORMAL
private static final AbstractJSON.WritingVisitor NORMAL
-
CANONICAL
private static final AbstractJSON.WritingVisitor CANONICAL
-
-
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 addedelement
- 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 propertyvalue
- the value of the propertyaccumulated
- 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.
-
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 interfaceJSON
- Throws:
java.io.IOException
-
write
protected abstract void write(java.io.Writer w, AbstractJSON.WritingVisitor v) throws java.io.IOException
- Throws:
java.io.IOException
-
-