Class JsonGenerator

java.lang.Object
uk.blankaspect.common.json.JsonGenerator

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

    • builder

      public static JsonGenerator.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(AbstractNode value)
      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, or null if there is no such token.
    • generate

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