Package uk.blankaspect.common.jsonxml
Class JsonGeneratorXml
java.lang.Object
uk.blankaspect.common.jsonxml.JsonGeneratorXml
This class implements a generator that transforms a tree of values that are represented by XML
elements 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.static class
This class implements an unchecked exception that is thrown in response to an unrecognised XML element. -
Method Summary
Modifier and TypeMethodDescriptionstatic JsonGeneratorXml.Builder
builder()
Creates and returns a new instance of a builder for a JSON generator.Generates and returns JSON text for the specified XML element in accordance with the properties of this generator: output mode, new line before left bracket parameter, indent increment, maximum line length.static JsonText.Token
Returns the JSON token that corresponds to the specified XML element.
-
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 XML element.- Parameters:
element
- the XML element whose corresponding JSON token is sought.- Returns:
- the JSON token that corresponds to
element
, ornull
if there is no such token.
-
generate
Generates and returns JSON text for the specified XML element in accordance with the properties of this generator:- output mode,
- new line before left bracket parameter,
- indent increment,
- maximum line length.
- Parameters:
value
- the XML element for which JSON text will be generated.- Returns:
- the JSON text that was generated for
value
. - Throws:
JsonGeneratorXml.UnrecognisedElementException
- if any element in the tree whose root isvalue
does not correspond to a JSON value.
-