Package net.morimekta.util.json
Class JsonWriter
- java.lang.Object
-
- net.morimekta.util.json.JsonWriter
-
- Direct Known Subclasses:
PrettyJsonWriter
public class JsonWriter extends java.lang.Object
IO-optimized JSON writer.
-
-
Constructor Summary
Constructors Constructor Description JsonWriter(java.io.OutputStream out)
JsonWriter(java.io.PrintWriter writer)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description JsonWriter
array()
Start an array value.JsonWriter
endArray()
End the ongoing array.JsonWriter
endObject()
The the ongoing object.void
flush()
Flush the internal writer.JsonWriter
key(boolean key)
Write the boolean as object key.JsonWriter
key(byte key)
Write the byte as object key.JsonWriter
key(double key)
Write the double as object key.JsonWriter
key(int key)
Write the int as object key.JsonWriter
key(long key)
Write the long as object key.JsonWriter
key(short key)
Write the short as object key.JsonWriter
key(java.lang.CharSequence key)
Write the string as object key.JsonWriter
key(Binary key)
Write the binary as object key.JsonWriter
keyLiteral(java.lang.CharSequence key)
Write the string key without quoting or escaping.JsonWriter
keyUnescaped(java.lang.CharSequence key)
Write the string as object key without escaping.JsonWriter
object()
Start an object value.protected void
reset()
Reset the state of the writer and flush already written content.protected void
startKey()
protected boolean
startValue()
JsonWriter
value(boolean value)
Write boolean value.JsonWriter
value(byte value)
Write byte value.JsonWriter
value(double value)
Write double value.JsonWriter
value(int value)
Write int value.JsonWriter
value(long value)
Write long value.JsonWriter
value(short value)
Write short value.JsonWriter
value(java.lang.CharSequence value)
Write unicode string value.JsonWriter
value(Binary value)
Write binary value.JsonWriter
valueLiteral(java.lang.CharSequence value)
Write a literal string as value.JsonWriter
valueUnescaped(java.lang.CharSequence value)
Write a string unescaped value.
-
-
-
Field Detail
-
kNull
public static final java.lang.String kNull
- See Also:
- Constant Field Values
-
kTrue
public static final java.lang.String kTrue
- See Also:
- Constant Field Values
-
kFalse
public static final java.lang.String kFalse
- See Also:
- Constant Field Values
-
context
protected net.morimekta.util.json.JsonContext context
-
-
Method Detail
-
reset
protected void reset()
Reset the state of the writer and flush already written content.
-
flush
public void flush()
Flush the internal writer.
-
object
public JsonWriter object()
Start an object value.- Returns:
- The JSON Writer.
-
array
public JsonWriter array()
Start an array value.- Returns:
- The JSON Writer.
-
endObject
public JsonWriter endObject()
The the ongoing object.- Returns:
- The JSON Writer.
-
endArray
public JsonWriter endArray()
End the ongoing array.- Returns:
- The JSON Writer.
-
key
public JsonWriter key(boolean key)
Write the boolean as object key.- Parameters:
key
- The boolean key.- Returns:
- The JSON Writer.
-
key
public JsonWriter key(byte key)
Write the byte as object key.- Parameters:
key
- The byte key.- Returns:
- The JSON Writer.
-
key
public JsonWriter key(short key)
Write the short as object key.- Parameters:
key
- The short key.- Returns:
- The JSON Writer.
-
key
public JsonWriter key(int key)
Write the int as object key.- Parameters:
key
- The int key.- Returns:
- The JSON Writer.
-
key
public JsonWriter key(long key)
Write the long as object key.- Parameters:
key
- The long key.- Returns:
- The JSON Writer.
-
key
public JsonWriter key(double key)
Write the double as object key.- Parameters:
key
- The double key.- Returns:
- The JSON Writer.
-
key
public JsonWriter key(java.lang.CharSequence key)
Write the string as object key.- Parameters:
key
- The string key.- Returns:
- The JSON Writer.
-
keyUnescaped
public JsonWriter keyUnescaped(java.lang.CharSequence key)
Write the string as object key without escaping.- Parameters:
key
- The string key.- Returns:
- The JSON Writer.
-
key
public JsonWriter key(Binary key)
Write the binary as object key.- Parameters:
key
- The binary key.- Returns:
- The JSON Writer.
-
keyLiteral
public JsonWriter keyLiteral(java.lang.CharSequence key)
Write the string key without quoting or escaping.- Parameters:
key
- The raw string key.- Returns:
- The JSON Writer.
-
value
public JsonWriter value(boolean value)
Write boolean value.- Parameters:
value
- The boolean value.- Returns:
- The JSON Writer.
-
value
public JsonWriter value(byte value)
Write byte value.- Parameters:
value
- The byte value.- Returns:
- The JSON Writer.
-
value
public JsonWriter value(short value)
Write short value.- Parameters:
value
- The short value.- Returns:
- The JSON Writer.
-
value
public JsonWriter value(int value)
Write int value.- Parameters:
value
- The int value.- Returns:
- The JSON Writer.
-
value
public JsonWriter value(long value)
Write long value.- Parameters:
value
- The long value.- Returns:
- The JSON Writer.
-
value
public JsonWriter value(double value)
Write double value.- Parameters:
value
- The double value.- Returns:
- The JSON Writer.
-
value
public JsonWriter value(java.lang.CharSequence value)
Write unicode string value.- Parameters:
value
- The string value.- Returns:
- The JSON Writer.
-
valueUnescaped
public JsonWriter valueUnescaped(java.lang.CharSequence value)
Write a string unescaped value.- Parameters:
value
- The string value.- Returns:
- The JSON Writer.
-
value
public JsonWriter value(Binary value)
Write binary value.- Parameters:
value
- The binary value.- Returns:
- The JSON Writer.
-
valueLiteral
public JsonWriter valueLiteral(java.lang.CharSequence value)
Write a literal string as value. Not quoted and not escaped.- Parameters:
value
- The raw string value.- Returns:
- The JSON Writer.
-
startKey
protected void startKey()
-
startValue
protected boolean startValue()
-
-