Package net.morimekta.util.json
Class PrettyJsonWriter
- java.lang.Object
-
- net.morimekta.util.json.JsonWriter
-
- net.morimekta.util.json.PrettyJsonWriter
-
public class PrettyJsonWriter extends JsonWriter
JSON Writer that automatically prints prettified JSON based on the inherent structure of the data. This is deliberately kept separate from the default JsonWriter to keep the indention logic away from the default JsonWriter (since it is pretty latency sensitive). Can be used in place of the default JsonWriter, and will print pretty- printed JSON out of the box. Default indentation is from the indented print writer, which is 4 spaces,
-
-
Field Summary
-
Fields inherited from class net.morimekta.util.json.JsonWriter
context, kFalse, kNull, kTrue
-
-
Constructor Summary
Constructors Constructor Description PrettyJsonWriter(java.io.OutputStream out)
Create a Prettified JSON writer that writes to the given output stream.PrettyJsonWriter(IndentedPrintWriter writer)
Create a Prettified JSON writer that writes to the given indented print writer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description PrettyJsonWriter
array()
Start an array value.PrettyJsonWriter
endArray()
End the ongoing array.PrettyJsonWriter
endObject()
The the ongoing object.PrettyJsonWriter
key(boolean key)
Write the boolean as object key.PrettyJsonWriter
key(byte key)
Write the byte as object key.PrettyJsonWriter
key(double key)
Write the double as object key.PrettyJsonWriter
key(int key)
Write the int as object key.PrettyJsonWriter
key(long key)
Write the long as object key.PrettyJsonWriter
key(short key)
Write the short as object key.PrettyJsonWriter
key(java.lang.CharSequence key)
Write the string as object key.PrettyJsonWriter
key(Binary key)
Write the binary as object key.PrettyJsonWriter
keyLiteral(java.lang.CharSequence key)
Write the string key without quoting or escaping.PrettyJsonWriter
keyUnescaped(java.lang.CharSequence key)
Write the string as object key without escaping.PrettyJsonWriter
object()
Start an object value.protected void
startKey()
protected boolean
startValue()
PrettyJsonWriter
value(boolean value)
Write boolean value.PrettyJsonWriter
value(byte value)
Write byte value.PrettyJsonWriter
value(double value)
Write double value.PrettyJsonWriter
value(int value)
Write int value.PrettyJsonWriter
value(long value)
Write long value.PrettyJsonWriter
value(short value)
Write short value.PrettyJsonWriter
value(java.lang.CharSequence value)
Write unicode string value.PrettyJsonWriter
value(Binary value)
Write binary value.PrettyJsonWriter
valueLiteral(java.lang.CharSequence value)
Write a literal string as value.PrettyJsonWriter
valueUnescaped(java.lang.CharSequence value)
Write a string unescaped value.-
Methods inherited from class net.morimekta.util.json.JsonWriter
flush, reset
-
-
-
-
Constructor Detail
-
PrettyJsonWriter
public PrettyJsonWriter(java.io.OutputStream out)
Create a Prettified JSON writer that writes to the given output stream.- Parameters:
out
- The stream to write to.
-
PrettyJsonWriter
public PrettyJsonWriter(IndentedPrintWriter writer)
Create a Prettified JSON writer that writes to the given indented print writer.- Parameters:
writer
- The writer to write to.
-
-
Method Detail
-
object
public PrettyJsonWriter object()
Description copied from class:JsonWriter
Start an object value.- Overrides:
object
in classJsonWriter
- Returns:
- The JSON Writer.
-
array
public PrettyJsonWriter array()
Description copied from class:JsonWriter
Start an array value.- Overrides:
array
in classJsonWriter
- Returns:
- The JSON Writer.
-
endObject
public PrettyJsonWriter endObject()
Description copied from class:JsonWriter
The the ongoing object.- Overrides:
endObject
in classJsonWriter
- Returns:
- The JSON Writer.
-
endArray
public PrettyJsonWriter endArray()
Description copied from class:JsonWriter
End the ongoing array.- Overrides:
endArray
in classJsonWriter
- Returns:
- The JSON Writer.
-
key
public PrettyJsonWriter key(boolean key)
Description copied from class:JsonWriter
Write the boolean as object key.- Overrides:
key
in classJsonWriter
- Parameters:
key
- The boolean key.- Returns:
- The JSON Writer.
-
key
public PrettyJsonWriter key(byte key)
Description copied from class:JsonWriter
Write the byte as object key.- Overrides:
key
in classJsonWriter
- Parameters:
key
- The byte key.- Returns:
- The JSON Writer.
-
key
public PrettyJsonWriter key(short key)
Description copied from class:JsonWriter
Write the short as object key.- Overrides:
key
in classJsonWriter
- Parameters:
key
- The short key.- Returns:
- The JSON Writer.
-
key
public PrettyJsonWriter key(int key)
Description copied from class:JsonWriter
Write the int as object key.- Overrides:
key
in classJsonWriter
- Parameters:
key
- The int key.- Returns:
- The JSON Writer.
-
key
public PrettyJsonWriter key(long key)
Description copied from class:JsonWriter
Write the long as object key.- Overrides:
key
in classJsonWriter
- Parameters:
key
- The long key.- Returns:
- The JSON Writer.
-
key
public PrettyJsonWriter key(double key)
Description copied from class:JsonWriter
Write the double as object key.- Overrides:
key
in classJsonWriter
- Parameters:
key
- The double key.- Returns:
- The JSON Writer.
-
key
public PrettyJsonWriter key(java.lang.CharSequence key)
Description copied from class:JsonWriter
Write the string as object key.- Overrides:
key
in classJsonWriter
- Parameters:
key
- The string key.- Returns:
- The JSON Writer.
-
key
public PrettyJsonWriter key(Binary key)
Description copied from class:JsonWriter
Write the binary as object key.- Overrides:
key
in classJsonWriter
- Parameters:
key
- The binary key.- Returns:
- The JSON Writer.
-
keyLiteral
public PrettyJsonWriter keyLiteral(java.lang.CharSequence key)
Description copied from class:JsonWriter
Write the string key without quoting or escaping.- Overrides:
keyLiteral
in classJsonWriter
- Parameters:
key
- The raw string key.- Returns:
- The JSON Writer.
-
keyUnescaped
public PrettyJsonWriter keyUnescaped(java.lang.CharSequence key)
Description copied from class:JsonWriter
Write the string as object key without escaping.- Overrides:
keyUnescaped
in classJsonWriter
- Parameters:
key
- The string key.- Returns:
- The JSON Writer.
-
value
public PrettyJsonWriter value(boolean value)
Description copied from class:JsonWriter
Write boolean value.- Overrides:
value
in classJsonWriter
- Parameters:
value
- The boolean value.- Returns:
- The JSON Writer.
-
value
public PrettyJsonWriter value(byte value)
Description copied from class:JsonWriter
Write byte value.- Overrides:
value
in classJsonWriter
- Parameters:
value
- The byte value.- Returns:
- The JSON Writer.
-
value
public PrettyJsonWriter value(short value)
Description copied from class:JsonWriter
Write short value.- Overrides:
value
in classJsonWriter
- Parameters:
value
- The short value.- Returns:
- The JSON Writer.
-
value
public PrettyJsonWriter value(int value)
Description copied from class:JsonWriter
Write int value.- Overrides:
value
in classJsonWriter
- Parameters:
value
- The int value.- Returns:
- The JSON Writer.
-
value
public PrettyJsonWriter value(long value)
Description copied from class:JsonWriter
Write long value.- Overrides:
value
in classJsonWriter
- Parameters:
value
- The long value.- Returns:
- The JSON Writer.
-
value
public PrettyJsonWriter value(double value)
Description copied from class:JsonWriter
Write double value.- Overrides:
value
in classJsonWriter
- Parameters:
value
- The double value.- Returns:
- The JSON Writer.
-
value
public PrettyJsonWriter value(java.lang.CharSequence value)
Description copied from class:JsonWriter
Write unicode string value.- Overrides:
value
in classJsonWriter
- Parameters:
value
- The string value.- Returns:
- The JSON Writer.
-
value
public PrettyJsonWriter value(Binary value)
Description copied from class:JsonWriter
Write binary value.- Overrides:
value
in classJsonWriter
- Parameters:
value
- The binary value.- Returns:
- The JSON Writer.
-
valueLiteral
public PrettyJsonWriter valueLiteral(java.lang.CharSequence value)
Description copied from class:JsonWriter
Write a literal string as value. Not quoted and not escaped.- Overrides:
valueLiteral
in classJsonWriter
- Parameters:
value
- The raw string value.- Returns:
- The JSON Writer.
-
valueUnescaped
public PrettyJsonWriter valueUnescaped(java.lang.CharSequence value)
Description copied from class:JsonWriter
Write a string unescaped value.- Overrides:
valueUnescaped
in classJsonWriter
- Parameters:
value
- The string value.- Returns:
- The JSON Writer.
-
startKey
protected void startKey()
- Overrides:
startKey
in classJsonWriter
-
startValue
protected boolean startValue()
- Overrides:
startValue
in classJsonWriter
-
-