Package com.aspectran.core.util.json
Class JsonWriter
- java.lang.Object
-
- com.aspectran.core.util.json.JsonWriter
-
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.AutoCloseable
- Direct Known Subclasses:
ContentsJsonWriter
public class JsonWriter extends java.lang.Object implements java.io.Flushable, java.io.CloseableConverts an object to a JSON formatted string.If pretty-printing is enabled, the JsonWriter will add newlines and indentation to the written data. Pretty-printing is disabled by default.
Created: 2008. 06. 12 PM 8:20:54
- Author:
- Juho Jeong
-
-
Constructor Summary
Constructors Constructor Description JsonWriter()Instantiates a new JsonWriter.JsonWriter(java.io.Writer out)Instantiates a new JsonWriter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbeginArray()Begins encoding a new array.voidbeginObject()Begins encoding a new object.voidclose()<T extends JsonWriter>
TdateFormat(java.lang.String dateFormat)<T extends JsonWriter>
TdateTimeFormat(java.lang.String dateTimeFormat)voidendArray()Ends encoding the current array.voidendObject()Ends encoding the current object.voidflush()Ensures all buffered data is written to the underlyingWriterand flushes that writer.<T extends JsonWriter>
TindentString(java.lang.String indentString)<T extends JsonWriter>
TnullWritable(boolean nullWritable)<T extends JsonWriter>
TprettyPrint(boolean prettyPrint)java.lang.StringtoString()<T extends JsonWriter>
Twrite(java.lang.Object object)Writes an object to the writer.voidwriteJson(java.lang.String json)Writes a string directly to the writer stream without quoting or escaping.voidwriteName(java.lang.String name)Writes a key name to the writer.voidwriteNull()Writes a "null" string to the writer.voidwriteNull(boolean force)Writes a "null" string to the writer.voidwriteValue(java.lang.Boolean value)Writes aBooleanobject to the writer.voidwriteValue(java.lang.Number value)Writes aNumberobject to the writer.voidwriteValue(java.lang.String value)Writes a string to the writer.
-
-
-
Constructor Detail
-
JsonWriter
public JsonWriter()
Instantiates a new JsonWriter. Pretty printing is enabled by default, and the indent string is set to " " (two spaces).
-
JsonWriter
public JsonWriter(java.io.Writer out)
Instantiates a new JsonWriter. Pretty printing is enabled by default, and the indent string is set to " " (two spaces).- Parameters:
out- the character-output stream
-
-
Method Detail
-
prettyPrint
public <T extends JsonWriter> T prettyPrint(boolean prettyPrint)
-
indentString
public <T extends JsonWriter> T indentString(java.lang.String indentString)
-
dateFormat
public <T extends JsonWriter> T dateFormat(java.lang.String dateFormat)
-
dateTimeFormat
public <T extends JsonWriter> T dateTimeFormat(java.lang.String dateTimeFormat)
-
nullWritable
public <T extends JsonWriter> T nullWritable(boolean nullWritable)
-
write
public <T extends JsonWriter> T write(java.lang.Object object) throws java.io.IOException
Writes an object to the writer.- Parameters:
object- the object to write to the writer.- Throws:
java.io.IOException- if an I/O error has occurred.
-
writeName
public void writeName(java.lang.String name)
Writes a key name to the writer.- Parameters:
name- the string to write to the writer
-
writeValue
public void writeValue(java.lang.String value) throws java.io.IOExceptionWrites a string to the writer. Ifvalueis null, write a null string ("").- Parameters:
value- the string to write to the writer- Throws:
java.io.IOException- if an I/O error has occurred
-
writeValue
public void writeValue(java.lang.Boolean value) throws java.io.IOExceptionWrites aBooleanobject to the writer.- Parameters:
value- aBooleanobject to write to the writer- Throws:
java.io.IOException- if an I/O error has occurred
-
writeValue
public void writeValue(java.lang.Number value) throws java.io.IOExceptionWrites aNumberobject to the writer.- Parameters:
value- aNumberobject to write to the writer- Throws:
java.io.IOException- if an I/O error has occurred
-
writeNull
public void writeNull() throws java.io.IOExceptionWrites a "null" string to the writer.- Throws:
java.io.IOException- if an I/O error has occurred
-
writeNull
public void writeNull(boolean force) throws java.io.IOExceptionWrites a "null" string to the writer.- Parameters:
force- true if forces should be written null value- Throws:
java.io.IOException- if an I/O error has occurred
-
writeJson
public void writeJson(java.lang.String json) throws java.io.IOExceptionWrites a string directly to the writer stream without quoting or escaping.- Parameters:
json- the string to write to the writer- Throws:
java.io.IOException- if an I/O error has occurred
-
beginObject
public void beginObject() throws java.io.IOExceptionBegins encoding a new object.- Throws:
java.io.IOException- if an I/O error has occurred
-
endObject
public void endObject() throws java.io.IOExceptionEnds encoding the current object.- Throws:
java.io.IOException- if an I/O error has occurred
-
beginArray
public void beginArray() throws java.io.IOExceptionBegins encoding a new array.- Throws:
java.io.IOException- if an I/O error has occurred
-
endArray
public void endArray() throws java.io.IOExceptionEnds encoding the current array.- Throws:
java.io.IOException- if an I/O error has occurred
-
flush
public void flush() throws java.io.IOExceptionEnsures all buffered data is written to the underlyingWriterand flushes that writer.- Specified by:
flushin interfacejava.io.Flushable- Throws:
java.io.IOException- if an I/O error has occurred
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-