Package uk.blankaspect.common.json
Class JsonGenerator
java.lang.Object
uk.blankaspect.common.json.JsonGenerator
This class implements a generator that transforms a tree of values that are represented by nodes into JSON text. The generator operates in one of several output modes, which
control the way in which whitespace is written between the tokens of the JSON text.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
This class implements a builder for a JSON generator. -
Method Summary
Modifier and TypeMethodDescriptionstatic JsonGenerator.Builder
builder()
Creates and returns a new instance of a builder for a JSON generator.generate
(AbstractNode value) Generates and returns JSON text for the specified value in accordance with the properties of this generator: output mode, new line before left bracket parameter, indent increment, maximum line length.static JsonText.Token
getToken
(AbstractNode value) Returns the JSON token that corresponds to the specified value.
-
Method Details
-
builder
Creates and returns a new instance of a builder for a JSON generator.- Returns:
- a new instance of a builder for a JSON generator.
-
getToken
Returns the JSON token that corresponds to the specified value.- Parameters:
value
- the value whose corresponding JSON token is sought.- Returns:
- the JSON token that corresponds to
value
, ornull
if there is no such token.
-
generate
Generates and returns JSON text for the specified value in accordance with the properties of this generator:- output mode,
- new line before left bracket parameter,
- indent increment,
- maximum line length.
- Parameters:
value
- the value for which JSON text will be generated.- Returns:
- the JSON text that was generated for
value
. - Throws:
NodeTypeException
- if any node in the tree whose root isvalue
does not correspond to a JSON value.
-