Class JacksonJsonNode

java.lang.Object
org.camunda.spin.Spin<SpinJsonNode>
org.camunda.spin.json.SpinJsonNode
org.camunda.spin.impl.json.jackson.JacksonJsonNode

public class JacksonJsonNode extends SpinJsonNode
Wrapper for a Jackson Json Tree Node.
Author:
Thorben Lindhauer, Stefan Hentschel
  • Field Details

    • jsonNode

      protected final com.fasterxml.jackson.databind.JsonNode jsonNode
    • dataFormat

      protected final JacksonJsonDataFormat dataFormat
  • Constructor Details

    • JacksonJsonNode

      public JacksonJsonNode(com.fasterxml.jackson.databind.JsonNode jsonNode, JacksonJsonDataFormat dataFormat)
  • Method Details

    • getDataFormatName

      public String getDataFormatName()
      Description copied from class: Spin
      Provides the name of the dataformat used by this spin.
      Specified by:
      getDataFormatName in class Spin<SpinJsonNode>
      Returns:
      the name of the dataformat used by this Spin.
    • unwrap

      public com.fasterxml.jackson.databind.JsonNode unwrap()
      Description copied from class: Spin
      Return the wrapped object. The return type of this method depends on the concrete data format.
      Specified by:
      unwrap in class Spin<SpinJsonNode>
      Returns:
      the object wrapped by this wrapper.
    • toString

      public String toString()
      Description copied from class: Spin
      Returns the wrapped object as string representation.
      Specified by:
      toString in class Spin<SpinJsonNode>
      Returns:
      the string representation
    • writeToWriter

      public void writeToWriter(Writer writer)
      Description copied from class: Spin
      Writes the wrapped object to a existing writer.
      Specified by:
      writeToWriter in class Spin<SpinJsonNode>
      Parameters:
      writer - the writer to write to
    • getCorrectIndex

      protected Integer getCorrectIndex(Integer index)
      fetch correct array index if index is less than 0 ArrayNode will convert all negative integers into 0...
      Parameters:
      index - wanted index
      Returns:
      Integer new index
    • lookupArray

      protected int lookupArray(com.fasterxml.jackson.databind.JsonNode searchNode, int direction)
    • indexOf

      public Integer indexOf(Object searchObject)
      Description copied from class: SpinJsonNode
      Fetches the first index of the searched object in an array.
      Specified by:
      indexOf in class SpinJsonNode
      Parameters:
      searchObject - Object for which the index should be searched.
      Returns:
      Integer index of searchObject.
    • lastIndexOf

      public Integer lastIndexOf(Object searchObject)
      Description copied from class: SpinJsonNode
      Fetches the last index of the searched object in an array.
      Specified by:
      lastIndexOf in class SpinJsonNode
      Parameters:
      searchObject - Object for which the index should be searched.
      Returns:
      Integer index of searchObject.
    • contains

      public boolean contains(Object searchObject)
      Description copied from class: SpinJsonNode
      Returns true if the array contains the specified object.
      Specified by:
      contains in class SpinJsonNode
      Parameters:
      searchObject - Object for which the array should be searched.
      Returns:
      true if the array contains the object.
    • isObject

      public boolean isObject()
      Description copied from class: SpinJsonNode
      Check if this node is an object node.
      Specified by:
      isObject in class SpinJsonNode
      Returns:
      true if the node is an object, false otherwise
    • hasProp

      public boolean hasProp(String name)
      Description copied from class: SpinJsonNode
      Check if this node has a property with the given name.
      Specified by:
      hasProp in class SpinJsonNode
      Parameters:
      name - the name of the property
      Returns:
      true if this node has a property with this name, false otherwise
    • prop

      public SpinJsonNode prop(String name)
      Description copied from class: SpinJsonNode
      Get the property of this node with the given name.
      Specified by:
      prop in class SpinJsonNode
      Parameters:
      name - the name of the property
      Returns:
      SpinJsonNode representation of the property
    • prop

      public SpinJsonNode prop(String name, String newProperty)
      Description copied from class: SpinJsonNode
      Set a new String property in this node.
      Specified by:
      prop in class SpinJsonNode
      Parameters:
      name - the name of the new property
      newProperty - the new String property
      Returns:
      SpinJsonNode representation of the current node
    • prop

      public SpinJsonNode prop(String name, Number newProperty)
      Description copied from class: SpinJsonNode
      Set a new Number property in this node.
      Specified by:
      prop in class SpinJsonNode
      Parameters:
      name - the name of the new property
      newProperty - the new Number property
      Returns:
      SpinJsonNode representation of the current node
    • prop

      public SpinJsonNode prop(String name, int newProperty)
      Description copied from class: SpinJsonNode
      Set a new int property in this node.
      Specified by:
      prop in class SpinJsonNode
      Parameters:
      name - the name of the new property
      newProperty - the new int property
      Returns:
      SpinJsonNode representation of the current node
    • prop

      public SpinJsonNode prop(String name, float newProperty)
      Description copied from class: SpinJsonNode
      Set a new float property in this node.
      Specified by:
      prop in class SpinJsonNode
      Parameters:
      name - the name of the new property
      newProperty - the new float property
      Returns:
      SpinJsonNode representation of the current node
    • prop

      public SpinJsonNode prop(String name, long newProperty)
      Description copied from class: SpinJsonNode
      Set a new long property in this node.
      Specified by:
      prop in class SpinJsonNode
      Parameters:
      name - the name of the new property
      newProperty - the new long property
      Returns:
      SpinJsonNode representation of the current node
    • prop

      public SpinJsonNode prop(String name, boolean newProperty)
      Description copied from class: SpinJsonNode
      Set a new boolean property in this node.
      Specified by:
      prop in class SpinJsonNode
      Parameters:
      name - the name of the new property
      newProperty - the new boolean property
      Returns:
      SpinJsonNode representation of the current node
    • prop

      public SpinJsonNode prop(String name, Boolean newProperty)
      Description copied from class: SpinJsonNode
      Set a new Boolean property in this node.
      Specified by:
      prop in class SpinJsonNode
      Parameters:
      name - the name of the new property
      newProperty - the new Boolean property
      Returns:
      SpinJsonNode representation of the current node
    • prop

      public SpinJsonNode prop(String name, List<Object> newProperty)
      Description copied from class: SpinJsonNode
      Set a new List property in this node.
      Specified by:
      prop in class SpinJsonNode
      Parameters:
      name - the name of the new property
      newProperty - the new List property
      Returns:
      SpinJsonNode representation of the current node
    • propList

      public SpinJsonNode propList(String name, List<Object> newProperty)
    • prop

      public SpinJsonNode prop(String name, Map<String,Object> newProperty)
      Description copied from class: SpinJsonNode
      Set a new Map property in this node.
      Specified by:
      prop in class SpinJsonNode
      Parameters:
      name - the name of the new property
      newProperty - the new Map property
      Returns:
      SpinJsonNode representation of the current node
    • prop

      public SpinJsonNode prop(String name, SpinJsonNode newProperty)
      Description copied from class: SpinJsonNode
      Set a new SpinJsonNode Object property in this node.
      Specified by:
      prop in class SpinJsonNode
      Parameters:
      name - the name of the new property
      newProperty - the new SpinJsonNode Object property
      Returns:
      SpinJsonNode representation of the current node
    • deleteProp

      public SpinJsonNode deleteProp(String name)
      Description copied from class: SpinJsonNode
      Remove a property of the given node by name.
      Specified by:
      deleteProp in class SpinJsonNode
      Parameters:
      name - name of the property
      Returns:
      SpinJsonNode representation of the current node
    • deleteProp

      public SpinJsonNode deleteProp(List<String> names)
      Description copied from class: SpinJsonNode
      Removes a number of properties by a given list of names.
      Specified by:
      deleteProp in class SpinJsonNode
      Parameters:
      names - list of names
      Returns:
      SpinJsonNode representation of the current node
    • append

      public SpinJsonNode append(Object property)
      Description copied from class: SpinJsonNode
      Appends a object to the end of the current array node
      Specified by:
      append in class SpinJsonNode
      Parameters:
      property - property which should be append
      Returns:
      SpinJsonNode representation of the current node
    • insertAt

      public SpinJsonNode insertAt(int index, Object property)
      Description copied from class: SpinJsonNode
      Appends an object at a specific point in an array
      Specified by:
      insertAt in class SpinJsonNode
      Parameters:
      index - Index in current node where the new property should be appended.
      property - Object which should be appended.
      Returns:
      SpinJsonNode representation of the current node.
    • insertBefore

      public SpinJsonNode insertBefore(Object searchObject, Object insertObject)
      Description copied from class: SpinJsonNode
      Inserts an object BEFORE an specific object in an array
      Specified by:
      insertBefore in class SpinJsonNode
      Parameters:
      searchObject - Object which is searched
      insertObject - Object which will be inserted
      Returns:
      SpinJsonNode representation of the current node
    • insertAfter

      public SpinJsonNode insertAfter(Object searchObject, Object insertObject)
      Description copied from class: SpinJsonNode
      Inserts an object AFTER an specific object in an array
      Specified by:
      insertAfter in class SpinJsonNode
      Parameters:
      searchObject - Object which is searched
      insertObject - Object which will be inserted
      Returns:
      SpinJsonNode representation of the current node
    • remove

      public SpinJsonNode remove(Object property)
      Description copied from class: SpinJsonNode
      Removes the first appearance of an object from the current array
      Specified by:
      remove in class SpinJsonNode
      Parameters:
      property - object which should be deleted
      Returns:
      SpinJsonNode representation of the current node
    • removeLast

      public SpinJsonNode removeLast(Object property)
      Description copied from class: SpinJsonNode
      Removes the last appearance of an object from the current array
      Specified by:
      removeLast in class SpinJsonNode
      Parameters:
      property - object which should be deleted
      Returns:
      SpinJsonNode representation of the current node
    • removeAt

      public SpinJsonNode removeAt(int index)
      Description copied from class: SpinJsonNode
      removes an object at the specific index of the current array
      Specified by:
      removeAt in class SpinJsonNode
      Parameters:
      index - Index of the array
      Returns:
      SpinJsonNode representation of the current node
    • isBoolean

      public Boolean isBoolean()
      Description copied from class: SpinJsonNode
      Check if this node is a boolean value.
      Specified by:
      isBoolean in class SpinJsonNode
      Returns:
      true if this node is a boolean value, false otherwise
    • boolValue

      public Boolean boolValue()
      Description copied from class: SpinJsonNode
      Get this node as a boolean value.
      Specified by:
      boolValue in class SpinJsonNode
      Returns:
      the boolean value of this node
    • isNumber

      public Boolean isNumber()
      Description copied from class: SpinJsonNode
      Check if this node is a number value.
      Specified by:
      isNumber in class SpinJsonNode
      Returns:
      true if this node is a number value, false otherwise
    • numberValue

      public Number numberValue()
      Description copied from class: SpinJsonNode
      Get this node as a number value.
      Specified by:
      numberValue in class SpinJsonNode
      Returns:
      the number value of this node
    • isString

      public Boolean isString()
      Description copied from class: SpinJsonNode
      Check if this node is a string value.
      Specified by:
      isString in class SpinJsonNode
      Returns:
      true if this node is a string value, false otherwise
    • stringValue

      public String stringValue()
      Description copied from class: SpinJsonNode
      Get this node as a string value.
      Specified by:
      stringValue in class SpinJsonNode
      Returns:
      the string value of this node
    • isNull

      public Boolean isNull()
      Description copied from class: SpinJsonNode
      Check if this node represents a null value.
      Specified by:
      isNull in class SpinJsonNode
      Returns:
      true if this node is a null value, false otherwise
    • isValue

      public Boolean isValue()
      Description copied from class: SpinJsonNode
      Check if this node is a value.
      Specified by:
      isValue in class SpinJsonNode
      Returns:
      true if this node is a value, false otherwise
    • value

      public Object value()
      Description copied from class: SpinJsonNode
      Gets the actual value of the node, in case it is a Boolean/String/Number/Null node. In that case a Java Boolean/String/Number or null is returned.
      Specified by:
      value in class SpinJsonNode
      Returns:
      the value of this node
    • isArray

      public Boolean isArray()
      Description copied from class: SpinJsonNode
      Check if this node is a array value.
      Specified by:
      isArray in class SpinJsonNode
      Returns:
      true if this node is a array value, false otherwise
    • elements

      public SpinList<SpinJsonNode> elements()
      Description copied from class: SpinJsonNode
      Get this node as list. If the current node is an array, this method returns a SpinList which contains copies of all JSON nodes contained in the current node. Changes to the the elements in the list will not propagate to the original nodes.
      Specified by:
      elements in class SpinJsonNode
      Returns:
      the list value of this node
    • fieldNames

      public List<String> fieldNames()
      Description copied from class: SpinJsonNode
      Get the field names of this node (i.e. the property names).
      Specified by:
      fieldNames in class SpinJsonNode
      Returns:
      the list of field names
    • getNodeType

      public com.fasterxml.jackson.databind.node.JsonNodeType getNodeType()
    • jsonPath

      public SpinJsonPathQuery jsonPath(String expression)
      Description copied from class: SpinJsonNode
      Creates a JsonPath query on this element.
      Specified by:
      jsonPath in class SpinJsonNode
      Parameters:
      expression - the JsonPath expression
      Returns:
      the JsonPath query
    • mapTo

      public <C> C mapTo(Class<C> type)
      Maps the json represented by this object to a java object of the given type.
      Note: the desired target type is not validated and needs to be trusted.
      Specified by:
      mapTo in class Spin<SpinJsonNode>
      Parameters:
      type - the java class to map to
      Returns:
      the mapped object
      Throws:
      SpinJsonException - if the json representation cannot be mapped to the specified type
    • mapTo

      public <C> C mapTo(String type)
      Maps the json represented by this object to a java object of the given type. Argument is to be supplied in Jackson's canonical type string format (see ResolvedType.toCanonical()).
      Note: the desired target type is not validated and needs to be trusted.
      Specified by:
      mapTo in class Spin<SpinJsonNode>
      Parameters:
      type - the class name to map to
      Returns:
      the mapped object
      Throws:
      SpinJsonException - if the json representation cannot be mapped to the specified type
      SpinJsonDataFormatException - if the parameter does not match a valid type
    • mapTo

      public <C> C mapTo(com.fasterxml.jackson.databind.JavaType type)
      Maps the json represented by this object to a java object of the given type.
      Note: the desired target type is not validated and needs to be trusted.
      Throws:
      SpinJsonException - if the json representation cannot be mapped to the specified type