Package uk.blankaspect.common.json
Class JsonGenerator
java.lang.Object
uk.blankaspect.common.json.JsonGenerator
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
This is an enumeration of the modes that control the way in which whitespace is written between the tokens of the JSON text. -
Constructor Summary
ConstructorDescriptionCreates a new instance of a JSON generator with default values for the mode (NORMAL
), the opening bracket on the same line flag (false
), the indent increment (2) and the maximum line length (80).Creates a new instance of a JSON generator with the specified mode.JsonGenerator
(JsonGenerator.Mode mode, boolean openingBracketOnSameLine) Creates a new instance of a JSON generator with the specified mode and opening bracket on the same line flag.JsonGenerator
(JsonGenerator.Mode mode, boolean openingBracketOnSameLine, int indentIncrement, int maxLineLength) Creates a new instance of a JSON generator with the specified mode, opening bracket on the same line flag, indent increment and maximum line length. -
Method Summary
Modifier and TypeMethodDescriptiongenerate
(AbstractNode value) Generates and returns JSON text for the specified JSON value in accordance with the properties of this generator: mode, opening bracket on the same line flag, indent increment, maximum line length.
-
Constructor Details
-
JsonGenerator
public JsonGenerator()Creates a new instance of a JSON generator with default values for the mode (NORMAL
), the opening bracket on the same line flag (false
), the indent increment (2) and the maximum line length (80). -
JsonGenerator
Creates a new instance of a JSON generator with the specified mode. Default values will be used for the opening bracket on the same line flag (false
), the indent increment (2) and the maximum line length (80), which are applicable only in a multi-line mode (NORMAL
orEXPANDED
).- Parameters:
mode
- the mode of the generator, which controls the way in which whitespace is written between the tokens of the JSON text.
-
JsonGenerator
Creates a new instance of a JSON generator with the specified mode and opening bracket on the same line flag. Default values will be used for the indent increment (2) and the maximum line length (80), which are applicable only in a multi-line mode (NORMAL
orEXPANDED
).- Parameters:
mode
- the mode of the generator, which controls the way in which whitespace is written between the tokens of the JSON text.openingBracketOnSameLine
- iftrue
, the opening bracket of a JSON object or array will be written on the same line as the non-whitespace text that precedes it.
-
JsonGenerator
public JsonGenerator(JsonGenerator.Mode mode, boolean openingBracketOnSameLine, int indentIncrement, int maxLineLength) Creates a new instance of a JSON generator with the specified mode, opening bracket on the same line flag, indent increment and maximum line length.- Parameters:
mode
- the mode of the generator, which controls the way in which whitespace is written between the tokens of the JSON text.openingBracketOnSameLine
- iftrue
, the opening bracket of a JSON object or array will be written on the same line as the non-whitespace text that precedes it.indentIncrement
- the number of spaces by which indentation will be increased from one level to the next. This parameter has no effect in a single-line mode (DENSE
orCOMPACT
).maxLineLength
- the maximum length of a line of JSON text. This parameter has no effect in a single-line mode (DENSE
orCOMPACT
).
-
-
Method Details
-
generate
Generates and returns JSON text for the specified JSON value in accordance with the properties of this generator:- mode,
- opening bracket on the same line flag,
- indent increment,
- maximum line length.
- Parameters:
value
- the JSON value for which JSON text will be generated.- Returns:
- JSON text for value.
- Throws:
NodeTypeException
- if any node in the tree whose root is value does not represent a JSON value.
-