Class JsonGeneratorXml

java.lang.Object
uk.blankaspect.common.jsonxml.JsonGeneratorXml

public class JsonGeneratorXml extends Object
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.
  • Method Details

    • builder

      public static JsonGeneratorXml.Builder 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

      public static JsonText.Token getToken(Element element)
      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, or null if there is no such token.
    • generate

      public JsonText generate(Element value)
      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 is value does not correspond to a JSON value.