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.Closeable
Converts 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
Modifier and Type Method Description void
beginArray()
Open a single square bracket.void
beginBlock()
Open a single curly bracket.void
close()
<T extends JsonWriter>
TdateFormat(java.lang.String dateFormat)
<T extends JsonWriter>
TdateTimeFormat(java.lang.String dateTimeFormat)
void
endArray()
Close the open square bracket.void
endBlock()
Close the open curly bracket.void
flush()
protected void
indent()
Write a tab character to a character stream.<T extends JsonWriter>
TindentString(java.lang.String indentString)
protected void
nextLine()
Write a new line character to a character stream.<T extends JsonWriter>
TnullWritable(boolean nullWritable)
<T extends JsonWriter>
TprettyPrint(boolean prettyPrint)
java.lang.String
toString()
<T extends JsonWriter>
Twrite(java.lang.Object object)
Write an object to a character stream.void
writeComma()
Write a comma character to a character stream.void
writeName(java.lang.String name)
Writes a key name to a character stream.void
writeNull()
Write a string "null" to a character stream.void
writeNull(boolean force)
void
writeValue(java.lang.Boolean value)
Writes aBoolean
object to a character stream.void
writeValue(java.lang.Number value)
Writes aNumber
object to a character stream.void
writeValue(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.IOException
Writes a string to a character stream. Ifvalue
is 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.IOException
Writes aBoolean
object to a character stream.- Parameters:
value
- aBoolean
object 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.IOException
Writes aNumber
object to a character stream.- Parameters:
value
- aNumber
object 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.IOException
Write 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.IOException
Write 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.IOException
Open a single curly bracket.- Throws:
java.io.IOException
- if an I/O error has occurred
-
endBlock
public void endBlock() throws java.io.IOException
Close the open curly bracket.- Throws:
java.io.IOException
- if an I/O error has occurred
-
beginArray
public void beginArray() throws java.io.IOException
Open a single square bracket.- Throws:
java.io.IOException
- if an I/O error has occurred
-
endArray
public void endArray() throws java.io.IOException
Close the open square bracket.- Throws:
java.io.IOException
- if an I/O error has occurred
-
indent
protected void indent() throws java.io.IOException
Write 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.IOException
Write 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:
flush
in interfacejava.io.Flushable
- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
java.io.IOException
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-