java.lang.Object
com.northconcepts.datapipeline.json.builder.JsonNode
Direct Known Subclasses:
JsonField, JsonFragment, JsonValue

public abstract class JsonNode extends Object
Base class for the nodes of a JsonTemplate; each writes its opening and closing JSON to a Jackson generator.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected final <T extends JsonNode>
    T
    add(T node)
    Appends the node as a child and returns the added node.
    protected JsonArray
    Adds an anonymous array element and returns it; only arrays (and the template root) accept one.
    protected JsonArray
    array(String nameExpression)
    Adds an array-valued field and returns the new array; only valid on object nodes.
    protected void
    assertType(JsonNodeType type, String message)
    Throws a DataException with the given message unless this node is of the given type.
    Adds and returns the detail marker; the nodes added to it are written once for each record.
    protected DataException
    Wraps the throwable in a DataException with this node's type, class and children; subclasses add their own details.
    protected JsonNode
    field(String nameExpression, String valueExpression)
    Adds a scalar field whose name and value are computed by the given expressions; only valid on object nodes.
    getNodes(ExpressionContext context)
    Returns this node's children; a conditional node returns null when its condition is false in the given context.
    abstract JsonNodeType
    Returns the kind of JSON this node represents, which determines the child nodes it accepts.
    boolean
    hasNodes(ExpressionContext context)
    Returns true if this node has children to write in the given context; a conditional node also requires its condition.
    boolean
    Returns true for the JsonDetailMarker that marks where each record is written.
    protected JsonObject
    Adds an anonymous object element and returns it; only arrays (and the template root) accept one.
    protected JsonObject
    object(String nameExpression)
    Adds an object-valued field and returns the new object; only valid on object nodes.
    protected JsonNode
    value(String valueExpression)
    Adds a scalar element whose value is computed by the given expression; only valid on array nodes.
    when(String condition)
    Adds and returns a fragment whose nodes are written only when the given logical expression is true.
    final void
    writeEnd(ExpressionContext context, com.fasterxml.jackson.core.JsonGenerator jsonGenerator)
    Writes this node's closing output, wrapping any failure in a DataException that describes the node.
    protected abstract void
    writeEndImpl(ExpressionContext context, com.fasterxml.jackson.core.JsonGenerator generator)
    Writes this node's closing output, if any (such as an end-object or end-array token), after its children.
    final void
    writeStart(ExpressionContext context, com.fasterxml.jackson.core.JsonGenerator jsonGenerator)
    Writes this node's opening output, wrapping any failure in a DataException that describes the node.
    protected abstract void
    writeStartImpl(ExpressionContext context, com.fasterxml.jackson.core.JsonGenerator generator)
    Writes this node's opening output, if any: a start-object or start-array token, a field name or a scalar value.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • JsonNode

      public JsonNode()
  • Method Details

    • getType

      public abstract JsonNodeType getType()
      Returns the kind of JSON this node represents, which determines the child nodes it accepts.
    • writeStartImpl

      protected abstract void writeStartImpl(ExpressionContext context, com.fasterxml.jackson.core.JsonGenerator generator) throws Throwable
      Writes this node's opening output, if any: a start-object or start-array token, a field name or a scalar value.
      Throws:
      Throwable
    • writeEndImpl

      protected abstract void writeEndImpl(ExpressionContext context, com.fasterxml.jackson.core.JsonGenerator generator) throws Throwable
      Writes this node's closing output, if any (such as an end-object or end-array token), after its children.
      Throws:
      Throwable
    • writeStart

      public final void writeStart(ExpressionContext context, com.fasterxml.jackson.core.JsonGenerator jsonGenerator)
      Writes this node's opening output, wrapping any failure in a DataException that describes the node.
    • writeEnd

      public final void writeEnd(ExpressionContext context, com.fasterxml.jackson.core.JsonGenerator jsonGenerator)
      Writes this node's closing output, wrapping any failure in a DataException that describes the node.
    • exception

      protected DataException exception(Throwable e)
      Wraps the throwable in a DataException with this node's type, class and children; subclasses add their own details.
    • getNodes

      public List<JsonNode> getNodes(ExpressionContext context)
      Returns this node's children; a conditional node returns null when its condition is false in the given context.
    • hasNodes

      public boolean hasNodes(ExpressionContext context)
      Returns true if this node has children to write in the given context; a conditional node also requires its condition.
    • isMarker

      public boolean isMarker()
      Returns true for the JsonDetailMarker that marks where each record is written.
    • add

      protected final <T extends JsonNode> T add(T node)
      Appends the node as a child and returns the added node.
    • object

      protected JsonObject object()
      Adds an anonymous object element and returns it; only arrays (and the template root) accept one.
    • array

      protected JsonArray array()
      Adds an anonymous array element and returns it; only arrays (and the template root) accept one.
    • value

      protected JsonNode value(String valueExpression)
      Adds a scalar element whose value is computed by the given expression; only valid on array nodes.
    • object

      protected JsonObject object(String nameExpression)
      Adds an object-valued field and returns the new object; only valid on object nodes.
    • array

      protected JsonArray array(String nameExpression)
      Adds an array-valued field and returns the new array; only valid on object nodes.
    • field

      protected JsonNode field(String nameExpression, String valueExpression)
      Adds a scalar field whose name and value are computed by the given expressions; only valid on object nodes.
    • when

      protected JsonConditionalNode when(String condition)
      Adds and returns a fragment whose nodes are written only when the given logical expression is true.
    • detail

      protected JsonDetailMarker detail()
      Adds and returns the detail marker; the nodes added to it are written once for each record.
    • assertType

      protected void assertType(JsonNodeType type, String message)
      Throws a DataException with the given message unless this node is of the given type.