Package org.apache.juneau.marshall.hjson
Class HjsonWriter
java.lang.Object
java.io.Writer
org.apache.juneau.marshall.serializer.SerializerWriter<HjsonWriter>
org.apache.juneau.marshall.hjson.HjsonWriter
- All Implemented Interfaces:
Closeable,Flushable,Appendable,AutoCloseable
Specialized writer for serializing Hjson format.
Extends SerializerWriter with Hjson-specific methods for quoteless strings,
multiline strings, and formatting options.
See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final booleanOmit root braces.protected final booleanWhether to add space after colon.protected final booleanUse multiline ''' for strings with newlines.protected final booleanUse newlines instead of commas between members.protected final booleanUse quoteless keys when safe.protected final booleanUse quoteless strings for simple values.Fields inherited from class org.apache.juneau.marshall.serializer.SerializerWriter
maxIndent, out, quoteChar, trimStrings, uriResolver, useWhitespace -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedHjsonWriter(Writer out, boolean useWhitespace, int maxIndent, boolean trimStrings, boolean useNewlineSeparators, boolean useQuotelessStrings, boolean useQuotelessKeys, boolean omitRootBraces, boolean useMultilineStrings, boolean spacedKeyValueSeparator, UriResolver uriResolver) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionarrayEnd()Writes array end.Writes array start.booleanisSimpleValue(String value) Returns whether the value can be written as quoteless.Writes key-value separator (: or : ).memberSeparator(int depth) Writes member separator (newline or comma).multilineString(String value) Writes a multiline string using ''' syntax.booleanneedsQuoting(String key) Returns whether the key needs quoting.objectEnd(boolean omitBraces, int depth) Writes object end, optionally omitting braces.objectStart(boolean omitBraces, int depth) Writes object start, optionally omitting braces.quotedString(String value) Writes a quoted string with JSON escaping.quotelessString(String value) Writes a quoteless string value.
-
Field Details
-
useNewlineSeparators
Use newlines instead of commas between members. -
useQuotelessStrings
Use quoteless strings for simple values. -
useQuotelessKeys
Use quoteless keys when safe. -
omitRootBraces
Omit root braces. -
useMultilineStrings
Use multiline ''' for strings with newlines. -
spacedKeyValueSeparator
Whether to add space after colon.
-
-
Constructor Details
-
HjsonWriter
protected HjsonWriter(Writer out, boolean useWhitespace, int maxIndent, boolean trimStrings, boolean useNewlineSeparators, boolean useQuotelessStrings, boolean useQuotelessKeys, boolean omitRootBraces, boolean useMultilineStrings, boolean spacedKeyValueSeparator, UriResolver uriResolver) Constructor.- Parameters:
out- The writer being wrapped.useWhitespace- Iftrue , use indentation and newlines.maxIndent- The maximum indentation level.trimStrings- Iftrue , trim strings before serialization.useNewlineSeparators- Use newlines instead of commas.useQuotelessStrings- Use quoteless strings for simple values.useQuotelessKeys- Use quoteless keys when safe.omitRootBraces- Omit root object braces.useMultilineStrings- Use ''' for multiline strings.spacedKeyValueSeparator- Add space after colon.uriResolver- The URI resolver.
-
-
Method Details
-
memberSeparator
Writes member separator (newline or comma).- Parameters:
depth- The current indentation depth.- Returns:
- This object.
-
keyValueSeparator
Writes key-value separator (: or : ).- Returns:
- This object.
-
objectStart
Writes object start, optionally omitting braces.- Parameters:
omitBraces- Iftrue , omit the opening brace.depth- The current indentation depth.- Returns:
- This object.
-
objectEnd
Writes object end, optionally omitting braces.- Parameters:
omitBraces- Iftrue , omit the closing brace.depth- The current indentation depth.- Returns:
- This object.
-
arrayStart
Writes array start.- Returns:
- This object.
-
arrayEnd
Writes array end.- Returns:
- This object.
-
needsQuoting
Returns whether the key needs quoting.- Parameters:
key- The key to check.
Can benull (returnstrue ).- Returns:
true if the key must be quoted.
-
isSimpleValue
Returns whether the value can be written as quoteless.- Parameters:
value- The value to check.
Can benull (returnsfalse ).- Returns:
true if the value can be quoteless.
-
quotelessString
Writes a quoteless string value.- Parameters:
value- The value to write.
Can benull (nothing is written).- Returns:
- This object.
-
quotedString
Writes a quoted string with JSON escaping.- Parameters:
value- The value to write.
Can benull (emitted as the literal"null" ).- Returns:
- This object.
-
multilineString
Writes a multiline string using ''' syntax.- Parameters:
value- The value to write.
Can benull (emitted as the literal"null" ).- Returns:
- This object.
-