Class JacksonJsonNode


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

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      SpinJsonNode append​(java.lang.Object property)
      Appends a object to the end of the current array node
      java.lang.Boolean boolValue()
      Get this node as a boolean value.
      boolean contains​(java.lang.Object searchObject)
      Returns true if the array contains the specified object.
      SpinJsonNode deleteProp​(java.lang.String name)
      Remove a property of the given node by name.
      SpinJsonNode deleteProp​(java.util.List<java.lang.String> names)
      Removes a number of properties by a given list of names.
      SpinList<SpinJsonNode> elements()
      Get this node as list.
      java.util.List<java.lang.String> fieldNames()
      Get the field names of this node (i.e.
      protected java.lang.Integer getCorrectIndex​(java.lang.Integer index)
      fetch correct array index if index is less than 0 ArrayNode will convert all negative integers into 0...
      java.lang.String getDataFormatName()
      Provides the name of the dataformat used by this spin.
      com.fasterxml.jackson.databind.node.JsonNodeType getNodeType()  
      boolean hasProp​(java.lang.String name)
      Check if this node has a property with the given name.
      java.lang.Integer indexOf​(java.lang.Object searchObject)
      Fetches the first index of the searched object in an array.
      SpinJsonNode insertAfter​(java.lang.Object searchObject, java.lang.Object insertObject)
      Inserts an object AFTER an specific object in an array
      SpinJsonNode insertAt​(int index, java.lang.Object property)
      Appends an object at a specific point in an array
      SpinJsonNode insertBefore​(java.lang.Object searchObject, java.lang.Object insertObject)
      Inserts an object BEFORE an specific object in an array
      java.lang.Boolean isArray()
      Check if this node is a array value.
      java.lang.Boolean isBoolean()
      Check if this node is a boolean value.
      java.lang.Boolean isNull()
      Check if this node represents a null value.
      java.lang.Boolean isNumber()
      Check if this node is a number value.
      boolean isObject()
      Check if this node is an object node.
      java.lang.Boolean isString()
      Check if this node is a string value.
      java.lang.Boolean isValue()
      Check if this node is a value.
      SpinJsonPathQuery jsonPath​(java.lang.String expression)
      Creates a JsonPath query on this element.
      java.lang.Integer lastIndexOf​(java.lang.Object searchObject)
      Fetches the last index of the searched object in an array.
      protected int lookupArray​(com.fasterxml.jackson.databind.JsonNode searchNode, int direction)  
      <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.
      <C> C mapTo​(java.lang.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.
      <C> C mapTo​(java.lang.String type)
      Maps the json represented by this object to a java object of the given type.
      java.lang.Number numberValue()
      Get this node as a number value.
      SpinJsonNode prop​(java.lang.String name)
      Get the property of this node with the given name.
      SpinJsonNode prop​(java.lang.String name, boolean newProperty)
      Set a new boolean property in this node.
      SpinJsonNode prop​(java.lang.String name, float newProperty)
      Set a new float property in this node.
      SpinJsonNode prop​(java.lang.String name, int newProperty)
      Set a new int property in this node.
      SpinJsonNode prop​(java.lang.String name, long newProperty)
      Set a new long property in this node.
      SpinJsonNode prop​(java.lang.String name, java.lang.Boolean newProperty)
      Set a new Boolean property in this node.
      SpinJsonNode prop​(java.lang.String name, java.lang.Number newProperty)
      Set a new Number property in this node.
      SpinJsonNode prop​(java.lang.String name, java.lang.String newProperty)
      Set a new String property in this node.
      SpinJsonNode prop​(java.lang.String name, java.util.List<java.lang.Object> newProperty)
      Set a new List property in this node.
      SpinJsonNode prop​(java.lang.String name, java.util.Map<java.lang.String,​java.lang.Object> newProperty)
      Set a new Map property in this node.
      SpinJsonNode prop​(java.lang.String name, SpinJsonNode newProperty)
      Set a new SpinJsonNode Object property in this node.
      SpinJsonNode propList​(java.lang.String name, java.util.List<java.lang.Object> newProperty)  
      SpinJsonNode remove​(java.lang.Object property)
      Removes the first appearance of an object from the current array
      SpinJsonNode removeAt​(int index)
      removes an object at the specific index of the current array
      SpinJsonNode removeLast​(java.lang.Object property)
      Removes the last appearance of an object from the current array
      java.lang.String stringValue()
      Get this node as a string value.
      java.lang.String toString()
      Returns the wrapped object as string representation.
      com.fasterxml.jackson.databind.JsonNode unwrap()
      Return the wrapped object.
      java.lang.Object value()
      Gets the actual value of the node, in case it is a Boolean/String/Number/Null node.
      void writeToWriter​(java.io.Writer writer)
      Writes the wrapped object to a existing writer.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • jsonNode

        protected final com.fasterxml.jackson.databind.JsonNode jsonNode
    • Constructor Detail

      • JacksonJsonNode

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

      • getDataFormatName

        public java.lang.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 java.lang.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​(java.io.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 java.lang.Integer getCorrectIndex​(java.lang.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 java.lang.Integer indexOf​(java.lang.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 java.lang.Integer lastIndexOf​(java.lang.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​(java.lang.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​(java.lang.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​(java.lang.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​(java.lang.String name,
                                 java.lang.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​(java.lang.String name,
                                 java.lang.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​(java.lang.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​(java.lang.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​(java.lang.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​(java.lang.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​(java.lang.String name,
                                 java.lang.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​(java.lang.String name,
                                 java.util.List<java.lang.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​(java.lang.String name,
                                     java.util.List<java.lang.Object> newProperty)
      • prop

        public SpinJsonNode prop​(java.lang.String name,
                                 java.util.Map<java.lang.String,​java.lang.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​(java.lang.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​(java.lang.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​(java.util.List<java.lang.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​(java.lang.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,
                                     java.lang.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​(java.lang.Object searchObject,
                                         java.lang.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​(java.lang.Object searchObject,
                                        java.lang.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​(java.lang.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​(java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.util.List<java.lang.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​(java.lang.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​(java.lang.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​(java.lang.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