Class SpinJsonNode

  • Direct Known Subclasses:
    JacksonJsonNode

    public abstract class SpinJsonNode
    extends Spin<SpinJsonNode>
    A json node.
    Author:
    Thorben Lindhauer, Stefan Hentschel
    • Constructor Summary

      Constructors 
      Constructor Description
      SpinJsonNode()  
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      abstract SpinJsonNode append​(java.lang.Object property)
      Appends a object to the end of the current array node
      abstract java.lang.Boolean boolValue()
      Get this node as a boolean value.
      abstract boolean contains​(java.lang.Object searchObject)
      Returns true if the array contains the specified object.
      abstract SpinJsonNode deleteProp​(java.lang.String name)
      Remove a property of the given node by name.
      abstract SpinJsonNode deleteProp​(java.util.List<java.lang.String> names)
      Removes a number of properties by a given list of names.
      abstract SpinList<SpinJsonNode> elements()
      Get this node as list.
      abstract java.util.List<java.lang.String> fieldNames()
      Get the field names of this node (i.e.
      abstract boolean hasProp​(java.lang.String name)
      Check if this node has a property with the given name.
      abstract java.lang.Integer indexOf​(java.lang.Object searchObject)
      Fetches the first index of the searched object in an array.
      abstract SpinJsonNode insertAfter​(java.lang.Object searchObject, java.lang.Object insertObject)
      Inserts an object AFTER an specific object in an array
      abstract SpinJsonNode insertAt​(int index, java.lang.Object property)
      Appends an object at a specific point in an array
      abstract SpinJsonNode insertBefore​(java.lang.Object searchObject, java.lang.Object insertObject)
      Inserts an object BEFORE an specific object in an array
      abstract java.lang.Boolean isArray()
      Check if this node is a array value.
      abstract java.lang.Boolean isBoolean()
      Check if this node is a boolean value.
      abstract java.lang.Boolean isNull()
      Check if this node represents a null value.
      abstract java.lang.Boolean isNumber()
      Check if this node is a number value.
      abstract boolean isObject()
      Check if this node is an object node.
      abstract java.lang.Boolean isString()
      Check if this node is a string value.
      abstract java.lang.Boolean isValue()
      Check if this node is a value.
      abstract SpinJsonPathQuery jsonPath​(java.lang.String expression)
      Creates a JsonPath query on this element.
      abstract java.lang.Integer lastIndexOf​(java.lang.Object searchObject)
      Fetches the last index of the searched object in an array.
      abstract java.lang.Number numberValue()
      Get this node as a number value.
      abstract SpinJsonNode prop​(java.lang.String name)
      Get the property of this node with the given name.
      abstract SpinJsonNode prop​(java.lang.String name, boolean newProperty)
      Set a new boolean property in this node.
      abstract SpinJsonNode prop​(java.lang.String name, float newProperty)
      Set a new float property in this node.
      abstract SpinJsonNode prop​(java.lang.String name, int newProperty)
      Set a new int property in this node.
      abstract SpinJsonNode prop​(java.lang.String name, long newProperty)
      Set a new long property in this node.
      abstract SpinJsonNode prop​(java.lang.String name, java.lang.Boolean newProperty)
      Set a new Boolean property in this node.
      abstract SpinJsonNode prop​(java.lang.String name, java.lang.Number newProperty)
      Set a new Number property in this node.
      abstract SpinJsonNode prop​(java.lang.String name, java.lang.String newProperty)
      Set a new String property in this node.
      abstract SpinJsonNode prop​(java.lang.String name, java.util.List<java.lang.Object> newProperty)
      Set a new List property in this node.
      abstract SpinJsonNode prop​(java.lang.String name, java.util.Map<java.lang.String,​java.lang.Object> newProperty)
      Set a new Map property in this node.
      abstract SpinJsonNode prop​(java.lang.String name, SpinJsonNode newProperty)
      Set a new SpinJsonNode Object property in this node.
      abstract SpinJsonNode remove​(java.lang.Object property)
      Removes the first appearance of an object from the current array
      abstract SpinJsonNode removeAt​(int index)
      removes an object at the specific index of the current array
      abstract SpinJsonNode removeLast​(java.lang.Object property)
      Removes the last appearance of an object from the current array
      abstract java.lang.String stringValue()
      Get this node as a string value.
      abstract java.lang.Object value()
      Gets the actual value of the node, in case it is a Boolean/String/Number/Null node.
      • Methods inherited from class java.lang.Object

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

      • SpinJsonNode

        public SpinJsonNode()
    • Method Detail

      • indexOf

        public abstract java.lang.Integer indexOf​(java.lang.Object searchObject)
        Fetches the first index of the searched object in an array.
        Parameters:
        searchObject - Object for which the index should be searched.
        Returns:
        Integer index of searchObject.
        Throws:
        SpinJsonException - if the current node is not an array.
        SpinJsonPropertyException - if object is not found.
      • lastIndexOf

        public abstract java.lang.Integer lastIndexOf​(java.lang.Object searchObject)
        Fetches the last index of the searched object in an array.
        Parameters:
        searchObject - Object for which the index should be searched.
        Returns:
        Integer index of searchObject.
        Throws:
        SpinJsonException - if the current node is not an array.
        SpinJsonPropertyException - if object is not found.
      • contains

        public abstract boolean contains​(java.lang.Object searchObject)
        Returns true if the array contains the specified object.
        Parameters:
        searchObject - Object for which the array should be searched.
        Returns:
        true if the array contains the object.
        Throws:
        SpinJsonException - if the current node is not an array.
      • isObject

        public abstract boolean isObject()
        Check if this node is an object node.
        Returns:
        true if the node is an object, false otherwise
      • hasProp

        public abstract boolean hasProp​(java.lang.String name)
        Check if this node has a property with the given name.
        Parameters:
        name - the name of the property
        Returns:
        true if this node has a property with this name, false otherwise
      • prop

        public abstract SpinJsonNode prop​(java.lang.String name)
        Get the property of this node with the given name.
        Parameters:
        name - the name of the property
        Returns:
        SpinJsonNode representation of the property
      • prop

        public abstract SpinJsonNode prop​(java.lang.String name,
                                          java.lang.String newProperty)
        Set a new String property in this node.
        Parameters:
        name - the name of the new property
        newProperty - the new String property
        Returns:
        SpinJsonNode representation of the current node
      • prop

        public abstract SpinJsonNode prop​(java.lang.String name,
                                          java.lang.Number newProperty)
        Set a new Number property in this node.
        Parameters:
        name - the name of the new property
        newProperty - the new Number property
        Returns:
        SpinJsonNode representation of the current node
      • prop

        public abstract SpinJsonNode prop​(java.lang.String name,
                                          int newProperty)
        Set a new int property in this node.
        Parameters:
        name - the name of the new property
        newProperty - the new int property
        Returns:
        SpinJsonNode representation of the current node
      • prop

        public abstract SpinJsonNode prop​(java.lang.String name,
                                          float newProperty)
        Set a new float property in this node.
        Parameters:
        name - the name of the new property
        newProperty - the new float property
        Returns:
        SpinJsonNode representation of the current node
      • prop

        public abstract SpinJsonNode prop​(java.lang.String name,
                                          long newProperty)
        Set a new long property in this node.
        Parameters:
        name - the name of the new property
        newProperty - the new long property
        Returns:
        SpinJsonNode representation of the current node
      • prop

        public abstract SpinJsonNode prop​(java.lang.String name,
                                          boolean newProperty)
        Set a new boolean property in this node.
        Parameters:
        name - the name of the new property
        newProperty - the new boolean property
        Returns:
        SpinJsonNode representation of the current node
      • prop

        public abstract SpinJsonNode prop​(java.lang.String name,
                                          java.lang.Boolean newProperty)
        Set a new Boolean property in this node.
        Parameters:
        name - the name of the new property
        newProperty - the new Boolean property
        Returns:
        SpinJsonNode representation of the current node
      • prop

        public abstract SpinJsonNode prop​(java.lang.String name,
                                          java.util.List<java.lang.Object> newProperty)
        Set a new List property in this node.
        Parameters:
        name - the name of the new property
        newProperty - the new List property
        Returns:
        SpinJsonNode representation of the current node
      • prop

        public abstract SpinJsonNode prop​(java.lang.String name,
                                          java.util.Map<java.lang.String,​java.lang.Object> newProperty)
        Set a new Map property in this node.
        Parameters:
        name - the name of the new property
        newProperty - the new Map property
        Returns:
        SpinJsonNode representation of the current node
      • prop

        public abstract SpinJsonNode prop​(java.lang.String name,
                                          SpinJsonNode newProperty)
        Set a new SpinJsonNode Object property in this node.
        Parameters:
        name - the name of the new property
        newProperty - the new SpinJsonNode Object property
        Returns:
        SpinJsonNode representation of the current node
      • deleteProp

        public abstract SpinJsonNode deleteProp​(java.lang.String name)
        Remove a property of the given node by name.
        Parameters:
        name - name of the property
        Returns:
        SpinJsonNode representation of the current node
      • deleteProp

        public abstract SpinJsonNode deleteProp​(java.util.List<java.lang.String> names)
        Removes a number of properties by a given list of names.
        Parameters:
        names - list of names
        Returns:
        SpinJsonNode representation of the current node
      • append

        public abstract SpinJsonNode append​(java.lang.Object property)
        Appends a object to the end of the current array node
        Parameters:
        property - property which should be append
        Returns:
        SpinJsonNode representation of the current node
      • insertAt

        public abstract SpinJsonNode insertAt​(int index,
                                              java.lang.Object property)
        Appends an object at a specific point in an array
        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.
        Throws:
        java.lang.IllegalArgumentException - if index is out of bound.
      • insertBefore

        public abstract SpinJsonNode insertBefore​(java.lang.Object searchObject,
                                                  java.lang.Object insertObject)
        Inserts an object BEFORE an specific object in an array
        Parameters:
        searchObject - Object which is searched
        insertObject - Object which will be inserted
        Returns:
        SpinJsonNode representation of the current node
      • insertAfter

        public abstract SpinJsonNode insertAfter​(java.lang.Object searchObject,
                                                 java.lang.Object insertObject)
        Inserts an object AFTER an specific object in an array
        Parameters:
        searchObject - Object which is searched
        insertObject - Object which will be inserted
        Returns:
        SpinJsonNode representation of the current node
      • remove

        public abstract SpinJsonNode remove​(java.lang.Object property)
        Removes the first appearance of an object from the current array
        Parameters:
        property - object which should be deleted
        Returns:
        SpinJsonNode representation of the current node
      • removeLast

        public abstract SpinJsonNode removeLast​(java.lang.Object property)
        Removes the last appearance of an object from the current array
        Parameters:
        property - object which should be deleted
        Returns:
        SpinJsonNode representation of the current node
      • removeAt

        public abstract SpinJsonNode removeAt​(int index)
        removes an object at the specific index of the current array
        Parameters:
        index - Index of the array
        Returns:
        SpinJsonNode representation of the current node
        Throws:
        java.lang.IllegalArgumentException - if index is out of bound.
      • isBoolean

        public abstract java.lang.Boolean isBoolean()
        Check if this node is a boolean value.
        Returns:
        true if this node is a boolean value, false otherwise
      • boolValue

        public abstract java.lang.Boolean boolValue()
        Get this node as a boolean value.
        Returns:
        the boolean value of this node
        Throws:
        SpinDataFormatException - if this node is not a boolean value
      • isNumber

        public abstract java.lang.Boolean isNumber()
        Check if this node is a number value.
        Returns:
        true if this node is a number value, false otherwise
      • numberValue

        public abstract java.lang.Number numberValue()
        Get this node as a number value.
        Returns:
        the number value of this node
        Throws:
        SpinDataFormatException - if this node is not a number value
      • isString

        public abstract java.lang.Boolean isString()
        Check if this node is a string value.
        Returns:
        true if this node is a string value, false otherwise
      • stringValue

        public abstract java.lang.String stringValue()
        Get this node as a string value.
        Returns:
        the string value of this node
        Throws:
        SpinDataFormatException - if this node is not a string value
      • isNull

        public abstract java.lang.Boolean isNull()
        Check if this node represents a null value.
        Returns:
        true if this node is a null value, false otherwise
      • isValue

        public abstract java.lang.Boolean isValue()
        Check if this node is a value.
        Returns:
        true if this node is a value, false otherwise
      • value

        public abstract java.lang.Object value()
        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.
        Returns:
        the value of this node
        Throws:
        SpinDataFormatException - if this node is not a Boolean/String/Number/Nul value
      • isArray

        public abstract java.lang.Boolean isArray()
        Check if this node is a array value.
        Returns:
        true if this node is a array value, false otherwise
      • elements

        public abstract SpinList<SpinJsonNode> elements()
        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.
        Returns:
        the list value of this node
        Throws:
        SpinDataFormatException - if this node is not an array
      • fieldNames

        public abstract java.util.List<java.lang.String> fieldNames()
        Get the field names of this node (i.e. the property names).
        Returns:
        the list of field names
        Throws:
        SpinDataFormatException - if this node is not a array value
      • jsonPath

        public abstract SpinJsonPathQuery jsonPath​(java.lang.String expression)
        Creates a JsonPath query on this element.
        Parameters:
        expression - the JsonPath expression
        Returns:
        the JsonPath query