Package org.apache.juneau.json
Class JsonWriter
java.lang.Object
java.io.Writer
org.apache.juneau.serializer.SerializerWriter
org.apache.juneau.json.JsonWriter
- All Implemented Interfaces:
Closeable,Flushable,Appendable,AutoCloseable
Specialized writer for serializing JSON.
Notes:
- This class is not intended for external use.
See Also:
-
Field Summary
Fields inherited from class org.apache.juneau.serializer.SerializerWriter
maxIndent, out, quoteChar, trimStrings, uriResolver, useWhitespace -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedJsonWriter(Writer out, boolean useWhitespace, int maxIndent, boolean escapeSolidus, char quoteChar, boolean simpleAttrs, boolean trimStrings, UriResolver uriResolver) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionappend(char c) append(char[] value) Appends the specified characters to this writer.append(int indent, char c) Writes an indent (if theuseWhitespacesetting is enabled), followed by text.Writes an indent (if theuseWhitespacesetting is enabled), followed by text.Writes the specified text to the writer if it isn'tnull .Writes the specified text to the writer if it isn'tnull .appendIf(boolean b, char c) Writes the specified text to the writer if b is true.Writes the specified text to the writer if b is true.Writes an indent (if theuseWhitespacesetting is enabled), followed by text, followed by a newline (if theuseWhitespacesetting is enabled).Writes the specified text followed by a newline (if theuseWhitespacesetting is enabled).Appends the specified object as a URI.Serializes the specified object as a JSON attribute name.cr(int depth) Performs a carriage return.cre(int depth) Performs a carriage return at the end of a line.i(int indent) Writes an indent to the writer if theuseWhitespacesetting is enabled.ie(int indent) Writes an end-of-line indent to the writer if theuseWhitespacesetting is enabled.nl(int indent) Writes a newline to the writer if theuseWhitespacesetting is enabled.nlIf(boolean flag, int indent) Writes a newline to the writer if theuseWhitespacesetting is enabled and the boolean flag is true.q()Adds the quote character specified by thequoteCharsetting to the output.s()Adds a whitespace character to the output if theuseWhitespacesetting is enabled.s(int indent) Adds a space only if the current indentation level is below maxIndent.sIf(boolean flag) Writes a space if the boolean expression istrue anduseWhitespaceis false.smi(int depth) Performs an indentation only if we're currently past max indentation.Serializes the specified object as a JSON string value.Appends a URI to the output.w(char value) Writes the specified character to the writer.Writes the specified string to the writer.Methods inherited from class org.apache.juneau.serializer.SerializerWriter
close, flush, write
-
Constructor Details
-
JsonWriter
protected JsonWriter(Writer out, boolean useWhitespace, int maxIndent, boolean escapeSolidus, char quoteChar, boolean simpleAttrs, boolean trimStrings, UriResolver uriResolver) Constructor.- Parameters:
out- The writer being wrapped.useWhitespace- Iftrue , tabs and spaces will be used in output.maxIndent- The maximum indentation level.escapeSolidus- Iftrue , forward slashes should be escaped in the output.quoteChar- The quote character to use (i.e.'\'' or'"' )simpleAttrs- Iftrue , JSON attributes will only be quoted when necessary.trimStrings- Iftrue , strings will be trimmed before being serialized.uriResolver- The URI resolver for resolving URIs to absolute or root-relative form.
-
-
Method Details
-
append
- Specified by:
appendin interfaceAppendable- Overrides:
appendin classSerializerWriter
-
append
Description copied from class:SerializerWriterAppends the specified characters to this writer.- Overrides:
appendin classSerializerWriter- Parameters:
value- The characters to append to this writer.- Returns:
- This object.
-
append
Description copied from class:SerializerWriterWrites an indent (if theuseWhitespacesetting is enabled), followed by text.- Overrides:
appendin classSerializerWriter- Parameters:
indent- The number of tabs to indent.c- The character to write.- Returns:
- This object.
-
append
Description copied from class:SerializerWriterWrites an indent (if theuseWhitespacesetting is enabled), followed by text.- Overrides:
appendin classSerializerWriter- Parameters:
indent- The number of tabs to indent.text- The text to write.- Returns:
- This object.
-
append
Description copied from class:SerializerWriterWrites the specified text to the writer if it isn'tnull .- Overrides:
appendin classSerializerWriter- Parameters:
text- The text to write.- Returns:
- This object.
-
append
Description copied from class:SerializerWriterWrites the specified text to the writer if it isn'tnull .- Overrides:
appendin classSerializerWriter- Parameters:
text- The text to write.- Returns:
- This object.
-
appendIf
Description copied from class:SerializerWriterWrites the specified text to the writer if b is true.- Overrides:
appendIfin classSerializerWriter- Parameters:
b- Boolean flag.c- The text to write.- Returns:
- This object.
-
appendIf
Description copied from class:SerializerWriterWrites the specified text to the writer if b is true.- Overrides:
appendIfin classSerializerWriter- Parameters:
b- Boolean flag.text- The text to write.- Returns:
- This object.
-
appendln
Description copied from class:SerializerWriterWrites an indent (if theuseWhitespacesetting is enabled), followed by text, followed by a newline (if theuseWhitespacesetting is enabled).- Overrides:
appendlnin classSerializerWriter- Parameters:
indent- The number of tabs to indent.text- The text to write.- Returns:
- This object.
-
appendln
Description copied from class:SerializerWriterWrites the specified text followed by a newline (if theuseWhitespacesetting is enabled).- Overrides:
appendlnin classSerializerWriter- Parameters:
text- The text to write.- Returns:
- This object.
-
appendUri
Description copied from class:SerializerWriterAppends the specified object as a URI.Object is converted to a
String usingtoString() , so this will work onURLorURIobjects, or any other type that returns a URI via it'stoString() method.The URI is resolved based on the
Serializer.Builder.uriRelativity(UriRelativity)andSerializer.Builder.uriResolution(UriResolution)settings and theUriContextthat's part of the session.- Overrides:
appendUriin classSerializerWriter- Parameters:
value- The URI to serialize.- Returns:
- This object.
-
attr
Serializes the specified object as a JSON attribute name.- Parameters:
s- The object being serialized.- Returns:
- This object.
-
cr
Description copied from class:SerializerWriterPerforms a carriage return.Adds a newline and the specified number of tabs (if the
useWhitespacesetting is enabled) to the output.- Overrides:
crin classSerializerWriter- Parameters:
depth- The indentation.- Returns:
- This object.
-
cre
Description copied from class:SerializerWriterPerforms a carriage return at the end of a line.Adds a newline and the specified number of tabs (if the
useWhitespacesetting is enabled) to the output.- Overrides:
crein classSerializerWriter- Parameters:
depth- The indentation.- Returns:
- This object.
-
i
Description copied from class:SerializerWriterWrites an indent to the writer if theuseWhitespacesetting is enabled.- Overrides:
iin classSerializerWriter- Parameters:
indent- The number of tabs to indent.- Returns:
- This object.
-
ie
Description copied from class:SerializerWriterWrites an end-of-line indent to the writer if theuseWhitespacesetting is enabled.- Overrides:
iein classSerializerWriter- Parameters:
indent- The number of tabs to indent.- Returns:
- This object.
-
nl
Description copied from class:SerializerWriterWrites a newline to the writer if theuseWhitespacesetting is enabled.- Overrides:
nlin classSerializerWriter- Parameters:
indent- The current indentation level.- Returns:
- This object.
-
nlIf
Description copied from class:SerializerWriterWrites a newline to the writer if theuseWhitespacesetting is enabled and the boolean flag is true.- Overrides:
nlIfin classSerializerWriter- Parameters:
flag- The boolean flag.indent- The current indentation level.- Returns:
- This object.
-
q
Description copied from class:SerializerWriterAdds the quote character specified by thequoteCharsetting to the output.- Overrides:
qin classSerializerWriter- Returns:
- This object.
-
s
Description copied from class:SerializerWriterAdds a whitespace character to the output if theuseWhitespacesetting is enabled.- Overrides:
sin classSerializerWriter- Returns:
- This object.
-
s
Adds a space only if the current indentation level is below maxIndent.- Parameters:
indent- The number of spaces to indent.- Returns:
- This object.
-
sIf
Description copied from class:SerializerWriterWrites a space if the boolean expression istrue anduseWhitespaceis false.Intended for cases in XML where text should be separated by either a space or newline. This ensures the text is separated by a space if whitespace is disabled.
- Overrides:
sIfin classSerializerWriter- Parameters:
flag- The boolean flag.- Returns:
- This object.
-
smi
Performs an indentation only if we're currently past max indentation.- Parameters:
depth- The current indentation depth.- Returns:
- This object.
-
stringValue
Serializes the specified object as a JSON string value.- Parameters:
s- The object being serialized.- Returns:
- This object.
-
uriValue
Appends a URI to the output.- Parameters:
uri- The URI to append to the output.- Returns:
- This object.
-
w
Description copied from class:SerializerWriterWrites the specified character to the writer.- Overrides:
win classSerializerWriter- Parameters:
value- The character to write.- Returns:
- This object.
-
w
Description copied from class:SerializerWriterWrites the specified string to the writer.- Overrides:
win classSerializerWriter- Parameters:
value- The string to write.- Returns:
- This object.
-