Package org.cakelab.json.format
Class JSONFormatterBase<T extends java.io.PrintStream>
- java.lang.Object
-
- org.cakelab.json.format.JSONFormatterBase<T>
-
- All Implemented Interfaces:
JSONFormatter
- Direct Known Subclasses:
JSONFormatterCompact
,JSONFormatterPrettyprint
public abstract class JSONFormatterBase<T extends java.io.PrintStream> extends java.lang.Object implements JSONFormatter
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
JSONFormatterBase.IgnoringNullIterator
used when ignoring null entries in JSON objects
-
Field Summary
Fields Modifier and Type Field Description protected JSONFormatterConfiguration
cfg
protected static java.util.Comparator<java.util.Map.Entry<java.lang.String,java.lang.Object>>
ENTRY_COMPARATOR
-
Constructor Summary
Constructors Modifier Constructor Description protected
JSONFormatterBase(JSONFormatterConfiguration cfg)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract void
append(T pout, JSONArray o)
protected abstract void
append(T pout, JSONObject o)
protected void
appendAny(T pout, java.lang.Object anyJsonValue)
protected void
appendNewLine(T pout)
protected void
appendPrimitiveValue(T pout, java.lang.Object primitiveValue)
protected void
appendUnicodeCharacter(T pout, char c)
protected void
appendUnicodeString(T pout, java.lang.String str)
protected boolean
exceedsEncodingRange(char c)
void
format(java.io.OutputStream out, java.lang.Object jsonValue)
void
format(java.io.OutputStream out, JSONArray jsonArray)
void
format(java.io.OutputStream out, JSONCompoundType json)
void
format(java.io.OutputStream out, JSONObject jsonObject)
java.lang.String
format(java.lang.Object jsonValue)
java.lang.String
format(JSONArray jsonArray)
java.lang.String
format(JSONCompoundType json)
java.lang.String
format(JSONObject jsonObject)
JSONFormatterConfiguration
getConfiguration()
protected java.util.Iterator<java.util.Map.Entry<java.lang.String,java.lang.Object>>
iterator(java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.Object>> entrySet)
creates an iterator, which respects formatter configuration in respect to sorting of entries and ignoring of null values.protected abstract T
setupPrintStream(java.io.OutputStream out, boolean autoflush, java.lang.String charset)
called to setup a new PrintStream instance.
-
-
-
Field Detail
-
ENTRY_COMPARATOR
protected static final java.util.Comparator<java.util.Map.Entry<java.lang.String,java.lang.Object>> ENTRY_COMPARATOR
-
cfg
protected final JSONFormatterConfiguration cfg
-
-
Constructor Detail
-
JSONFormatterBase
protected JSONFormatterBase(JSONFormatterConfiguration cfg) throws JSONException
- Throws:
JSONException
-
-
Method Detail
-
getConfiguration
public JSONFormatterConfiguration getConfiguration()
- Specified by:
getConfiguration
in interfaceJSONFormatter
-
format
public java.lang.String format(JSONObject jsonObject) throws JSONException
- Specified by:
format
in interfaceJSONFormatter
- Throws:
JSONException
-
format
public java.lang.String format(JSONArray jsonArray) throws JSONException
- Specified by:
format
in interfaceJSONFormatter
- Throws:
JSONException
-
format
public java.lang.String format(java.lang.Object jsonValue) throws JSONException
- Specified by:
format
in interfaceJSONFormatter
- Throws:
JSONException
-
format
public java.lang.String format(JSONCompoundType json) throws JSONException
- Specified by:
format
in interfaceJSONFormatter
- Throws:
JSONException
-
format
public void format(java.io.OutputStream out, JSONCompoundType json) throws JSONException
- Specified by:
format
in interfaceJSONFormatter
- Throws:
JSONException
-
format
public void format(java.io.OutputStream out, JSONObject jsonObject) throws JSONException
- Specified by:
format
in interfaceJSONFormatter
- Throws:
JSONException
-
format
public void format(java.io.OutputStream out, JSONArray jsonArray) throws JSONException
- Specified by:
format
in interfaceJSONFormatter
- Throws:
JSONException
-
format
public void format(java.io.OutputStream out, java.lang.Object jsonValue) throws JSONException
- Specified by:
format
in interfaceJSONFormatter
- Throws:
JSONException
-
setupPrintStream
protected abstract T setupPrintStream(java.io.OutputStream out, boolean autoflush, java.lang.String charset) throws java.io.UnsupportedEncodingException
called to setup a new PrintStream instance.- Throws:
java.io.UnsupportedEncodingException
-
append
protected abstract void append(T pout, JSONArray o) throws JSONException
- Throws:
JSONException
-
append
protected abstract void append(T pout, JSONObject o) throws JSONException
- Throws:
JSONException
-
appendPrimitiveValue
protected void appendPrimitiveValue(T pout, java.lang.Object primitiveValue)
-
appendAny
protected void appendAny(T pout, java.lang.Object anyJsonValue) throws JSONException
- Throws:
JSONException
-
appendNewLine
protected void appendNewLine(T pout)
-
appendUnicodeString
protected void appendUnicodeString(T pout, java.lang.String str) throws JSONException
- Throws:
JSONException
-
appendUnicodeCharacter
protected void appendUnicodeCharacter(T pout, char c) throws JSONException
- Throws:
JSONException
-
exceedsEncodingRange
protected boolean exceedsEncodingRange(char c)
-
iterator
protected java.util.Iterator<java.util.Map.Entry<java.lang.String,java.lang.Object>> iterator(java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.Object>> entrySet)
creates an iterator, which respects formatter configuration in respect to sorting of entries and ignoring of null values.
-
-