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()Open a single square bracket.voidbeginBlock()Open a single curly bracket.voidclose()<T extends JsonWriter>
TdateFormat(java.lang.String dateFormat)<T extends JsonWriter>
TdateTimeFormat(java.lang.String dateTimeFormat)voidendArray()Close the open square bracket.voidendBlock()Close the open curly bracket.voidflush()protected voidindent()Write a tab character to a character stream.<T extends JsonWriter>
TindentString(java.lang.String indentString)protected voidnextLine()Write a new line character to a character stream.<T extends JsonWriter>
TnullWritable(boolean nullWritable)<T extends JsonWriter>
TprettyPrint(boolean prettyPrint)java.lang.StringtoString()<T extends JsonWriter>
Twrite(java.lang.Object object)Write an object to a character stream.voidwriteComma()Write a comma character to a character stream.voidwriteName(java.lang.String name)Writes a key name to a character stream.voidwriteNull()Write a string "null" to a character stream.voidwriteNull(boolean force)voidwriteValue(java.lang.Boolean value)Writes aBooleanobject to a character stream.voidwriteValue(java.lang.Number value)Writes aNumberobject to a character stream.voidwriteValue(java.lang.String value)Writes a string to a character stream.
-
-
-
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
Write an object to a character stream.- Parameters:
object- the object to write to a character-output stream.- Throws:
java.io.IOException- if an I/O error has occurred.
-
writeName
public void writeName(java.lang.String name)
Writes a key name to a character stream.- Parameters:
name- the string to write to a character-output stream
-
writeValue
public void writeValue(java.lang.String value) throws java.io.IOExceptionWrites a string to a character stream. Ifvalueis null, write a null string ("").- Parameters:
value- the string to write to a character-output stream- 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 a character stream.- Parameters:
value- aBooleanobject to write to a character-output stream- 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 a character stream.- Parameters:
value- aNumberobject to write to a character-output stream- Throws:
java.io.IOException- if an I/O error has occurred
-
writeNull
public void writeNull() throws java.io.IOExceptionWrite a string "null" to a character stream.- Throws:
java.io.IOException- if an I/O error has occurred
-
writeNull
public void writeNull(boolean force) throws java.io.IOException- Throws:
java.io.IOException
-
writeComma
public void writeComma() throws java.io.IOExceptionWrite a comma character to a character stream.- Throws:
java.io.IOException- if an I/O error has occurred
-
beginBlock
public void beginBlock() throws java.io.IOExceptionOpen a single curly bracket.- Throws:
java.io.IOException- if an I/O error has occurred
-
endBlock
public void endBlock() throws java.io.IOExceptionClose the open curly bracket.- Throws:
java.io.IOException- if an I/O error has occurred
-
beginArray
public void beginArray() throws java.io.IOExceptionOpen a single square bracket.- Throws:
java.io.IOException- if an I/O error has occurred
-
endArray
public void endArray() throws java.io.IOExceptionClose the open square bracket.- Throws:
java.io.IOException- if an I/O error has occurred
-
indent
protected void indent() throws java.io.IOExceptionWrite a tab character to a character stream.- Throws:
java.io.IOException- if an I/O error has occurred
-
nextLine
protected void nextLine() throws java.io.IOExceptionWrite a new line character to a character stream.- Throws:
java.io.IOException- if an I/O error has occurred
-
flush
public void flush() throws java.io.IOException- Specified by:
flushin interfacejava.io.Flushable- Throws:
java.io.IOException
-
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
-
-