Package com.aspectran.utils.json
Class JsonWriter
java.lang.Object
com.aspectran.utils.json.JsonWriter
- Direct Known Subclasses:
ContentsJsonWriter
,JsonWriterCloseable
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 -
Method Summary
Modifier and TypeMethodDescription<T extends JsonWriter>
Tapply
(StringifyContext stringifyContext) <T extends JsonWriter>
TBegins encoding a new array.<T extends JsonWriter>
TBegins encoding a new object.void
close()
<T extends JsonWriter>
TendArray()
Ends encoding the current array.<T extends JsonWriter>
TEnds encoding the current object.void
flush()
Ensures all buffered data is written to the underlyingWriter
and flushes that writer.<T extends JsonWriter>
TindentString
(String indentString) <T extends JsonWriter>
T<T extends JsonWriter>
TnullWritable
(boolean nullWritable) <T extends JsonWriter>
TprettyPrint
(boolean prettyPrint) void
setIndentString
(String indentString) void
setNullWritable
(boolean nullWritable) void
setPrettyPrint
(boolean prettyPrint) void
setStringifyContext
(StringifyContext stringifyContext) toString()
<T extends JsonWriter>
Tvoid
Writes a string directly to the writer stream without quoting or escaping.void
Writes a key name to the writer.void
Writes a "null" string to the writer.void
writeNull
(boolean force) Writes a "null" string to the writer.void
writeValue
(Object object) Writes an object to the writer.
-
Constructor Details
-
JsonWriter
Instantiates a new JsonWriter. Pretty printing is enabled by default, and the indent string is set to " " (two spaces).- Parameters:
writer
- the character-output stream
-
-
Method Details
-
setStringifyContext
-
apply
-
setPrettyPrint
public void setPrettyPrint(boolean prettyPrint) -
prettyPrint
-
setIndentString
-
indentString
-
setNullWritable
public void setNullWritable(boolean nullWritable) -
nullWritable
-
beginObject
Begins encoding a new object.- Throws:
IOException
- if an I/O error has occurred
-
endObject
Ends encoding the current object.- Throws:
IOException
- if an I/O error has occurred
-
beginArray
Begins encoding a new array.- Throws:
IOException
- if an I/O error has occurred
-
endArray
Ends encoding the current array.- Throws:
IOException
- if an I/O error has occurred
-
name
- Throws:
IOException
-
value
- Throws:
IOException
-
writeName
Writes a key name to the writer.- Parameters:
name
- the string to write to the writer
-
writeValue
Writes an object to the writer.- Parameters:
object
- the object to write to the writer.- Throws:
IOException
- if an I/O error has occurred.
-
writeNull
Writes a "null" string to the writer.- Throws:
IOException
- if an I/O error has occurred
-
writeNull
Writes a "null" string to the writer.- Parameters:
force
- true if forces should be written null value- Throws:
IOException
- if an I/O error has occurred
-
writeJson
Writes a string directly to the writer stream without quoting or escaping.- Parameters:
json
- the string to write to the writer- Throws:
IOException
- if an I/O error has occurred
-
flush
Ensures all buffered data is written to the underlyingWriter
and flushes that writer.- Throws:
IOException
- if an I/O error has occurred
-
close
- Throws:
IOException
-
toString
-