Package com.aspectran.utils.json
Class JsonWriter
java.lang.Object
com.aspectran.utils.json.JsonWriter
- Direct Known Subclasses:
ContentsJsonWriter
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
ConstructorsConstructorDescriptionInstantiates a new JsonWriter.JsonWriter
(Writer out) Instantiates a new JsonWriter. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Begins encoding a new array.void
Begins encoding a new object.void
close()
<T extends JsonWriter>
TdateFormat
(String dateFormat) <T extends JsonWriter>
TdateTimeFormat
(String dateTimeFormat) void
endArray()
Ends encoding the current array.void
Ends 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>
TnullWritable
(boolean nullWritable) <T extends JsonWriter>
TprettyPrint
(boolean prettyPrint) toString()
<T extends JsonWriter>
TWrites an object to the writer.void
Writes a string directly to the writer stream without quoting or escaping.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
(Boolean value) Writes aBoolean
object to the writer.void
writeValue
(Number value) Writes aNumber
object to the writer.void
writeValue
(String value) Writes a string to the writer.
-
Constructor Details
-
JsonWriter
public JsonWriter()Instantiates a new JsonWriter. Pretty printing is enabled by default, and the indent string is set to " " (two spaces). -
JsonWriter
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 Details
-
prettyPrint
-
indentString
-
dateFormat
-
dateTimeFormat
-
nullWritable
-
write
Writes an object to the writer.- Parameters:
object
- the object to write to the writer.- Throws:
IOException
- if an I/O error has occurred.
-
writeName
Writes a key name to the writer.- Parameters:
name
- the string to write to the writer
-
writeValue
Writes a string to the writer. Ifvalue
is null, write a null string ("").- Parameters:
value
- the string to write to the writer- Throws:
IOException
- if an I/O error has occurred
-
writeValue
Writes aBoolean
object to the writer.- Parameters:
value
- aBoolean
object to write to the writer- Throws:
IOException
- if an I/O error has occurred
-
writeValue
Writes aNumber
object to the writer.- Parameters:
value
- aNumber
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
-
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
-
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
-