Class JsonNode
java.lang.Object
com.northconcepts.datapipeline.json.builder.JsonNode
- Direct Known Subclasses:
JsonField,JsonFragment,JsonValue
Base class for the nodes of a
JsonTemplate; each writes its opening and closing JSON to a Jackson generator.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected final <T extends JsonNode>
Tadd(T node) Appends the node as a child and returns the added node.protected JsonArrayarray()Adds an anonymous array element and returns it; only arrays (and the template root) accept one.protected JsonArrayAdds an array-valued field and returns the new array; only valid on object nodes.protected voidassertType(JsonNodeType type, String message) Throws aDataExceptionwith the given message unless this node is of the given type.protected JsonDetailMarkerdetail()Adds and returns the detail marker; the nodes added to it are written once for each record.protected DataExceptionWraps the throwable in aDataExceptionwith this node's type, class and children; subclasses add their own details.protected JsonNodeAdds 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 JsonNodeTypegetType()Returns the kind of JSON this node represents, which determines the child nodes it accepts.booleanhasNodes(ExpressionContext context) Returns true if this node has children to write in the given context; a conditional node also requires its condition.booleanisMarker()Returns true for theJsonDetailMarkerthat marks where each record is written.protected JsonObjectobject()Adds an anonymous object element and returns it; only arrays (and the template root) accept one.protected JsonObjectAdds an object-valued field and returns the new object; only valid on object nodes.protected JsonNodeAdds a scalar element whose value is computed by the given expression; only valid on array nodes.protected JsonConditionalNodeAdds and returns a fragment whose nodes are written only when the given logical expression is true.final voidwriteEnd(ExpressionContext context, com.fasterxml.jackson.core.JsonGenerator jsonGenerator) Writes this node's closing output, wrapping any failure in aDataExceptionthat describes the node.protected abstract voidwriteEndImpl(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 voidwriteStart(ExpressionContext context, com.fasterxml.jackson.core.JsonGenerator jsonGenerator) Writes this node's opening output, wrapping any failure in aDataExceptionthat describes the node.protected abstract voidwriteStartImpl(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.
-
Constructor Details
-
JsonNode
public JsonNode()
-
-
Method Details
-
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 aDataExceptionthat 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 aDataExceptionthat describes the node. -
exception
Wraps the throwable in aDataExceptionwith this node's type, class and children; subclasses add their own details. -
getNodes
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 theJsonDetailMarkerthat marks where each record is written. -
add
Appends the node as a child and returns the added node. -
object
Adds an anonymous object element and returns it; only arrays (and the template root) accept one. -
array
Adds an anonymous array element and returns it; only arrays (and the template root) accept one. -
value
Adds a scalar element whose value is computed by the given expression; only valid on array nodes. -
object
Adds an object-valued field and returns the new object; only valid on object nodes. -
array
Adds an array-valued field and returns the new array; only valid on object nodes. -
field
Adds a scalar field whose name and value are computed by the given expressions; only valid on object nodes. -
when
Adds and returns a fragment whose nodes are written only when the given logical expression is true. -
detail
Adds and returns the detail marker; the nodes added to it are written once for each record. -
assertType
Throws aDataExceptionwith the given message unless this node is of the given type.
-