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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
beginArray()
Begins encoding a new array.void
beginObject()
Begins encoding a new object.void
close()
<T extends JsonWriter>
TdateFormat(java.lang.String dateFormat)
<T extends JsonWriter>
TdateTimeFormat(java.lang.String dateTimeFormat)
void
endArray()
Ends encoding the current array.void
endObject()
Ends encoding the current object.void
flush()
Ensures all buffered data is written to the underlyingWriter
and 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.String
toString()
<T extends JsonWriter>
Twrite(java.lang.Object object)
Writes an object to the writer.void
writeJson(java.lang.String json)
Writes a string directly to the writer stream without quoting or escaping.JsonWriter
writeName(java.lang.String name)
Writes a key name to the writer.void
writeNull()
Writes a "null" string to the writer.void
writeNull(boolean force)
Writes a "null" string to the writer.void
writeValue(java.lang.Boolean value)
Writes aBoolean
object to the writer.void
writeValue(java.lang.Number value)
Writes aNumber
object to the writer.void
writeValue(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 JsonWriter 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.IOException
Writes a string to the writer. Ifvalue
is 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.IOException
Writes aBoolean
object to the writer.- Parameters:
value
- aBoolean
object 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.IOException
Writes aNumber
object to the writer.- Parameters:
value
- aNumber
object to write to the writer- Throws:
java.io.IOException
- if an I/O error has occurred
-
writeNull
public void writeNull() throws java.io.IOException
Writes 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.IOException
Writes 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.IOException
Writes 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.IOException
Begins encoding a new object.- Throws:
java.io.IOException
- if an I/O error has occurred
-
endObject
public void endObject() throws java.io.IOException
Ends encoding the current object.- Throws:
java.io.IOException
- if an I/O error has occurred
-
beginArray
public void beginArray() throws java.io.IOException
Begins encoding a new array.- Throws:
java.io.IOException
- if an I/O error has occurred
-
endArray
public void endArray() throws java.io.IOException
Ends encoding the current array.- Throws:
java.io.IOException
- if an I/O error has occurred
-
flush
public void flush() throws java.io.IOException
Ensures all buffered data is written to the underlyingWriter
and flushes that writer.- Specified by:
flush
in interfacejava.io.Flushable
- Throws:
java.io.IOException
- if an I/O error has occurred
-
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
-
-