Package org.apache.juneau.marshall.json
Class JsonWriter<SELF extends JsonWriter<SELF>>
java.lang.Object
java.io.Writer
org.apache.juneau.marshall.serializer.SerializerWriter<SELF>
org.apache.juneau.marshall.json.JsonWriter<SELF>
- All Implemented Interfaces:
Closeable,Flushable,Appendable,AutoCloseable
- Direct Known Subclasses:
BasicJsonWriter,JcsWriter
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.marshall.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 TypeMethodDescriptionSerializes the specified object as a JSON attribute name.static BasicJsonWritercreate(Writer out, boolean useWhitespace, int maxIndent, boolean escapeSolidus, char quoteChar, boolean simpleAttrs, boolean trimStrings, UriResolver uriResolver) Creates a new JsonWriter instance.s(int indent) Adds a space only if the current indentation level is below maxIndent.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.
-
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
-
create
public static BasicJsonWriter create(Writer out, boolean useWhitespace, int maxIndent, boolean escapeSolidus, char quoteChar, boolean simpleAttrs, boolean trimStrings, UriResolver uriResolver) Creates a new JsonWriter instance.Provided for subclasses in other packages (e.g. Json5SerializerSession) that need to create JsonWriter instances.
- 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.- Returns:
- A new JsonWriter instance.
-
attr
Serializes the specified object as a JSON attribute name.- Parameters:
s- The object being serialized.
Can benull (emitted as the literal"null" ).- 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.
-
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.
Can benull (nothing is written).- Returns:
- This object.
-
uriValue
Appends a URI to the output.- Parameters:
uri- The URI to append to the output.- Returns:
- This object.
-