Class ValidationUtils


  • public class ValidationUtils
    extends Object
    Utility methods for validating segments of JSON API resource object.
    Author:
    jbegic
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void ensurePrimaryDataValidArray​(com.fasterxml.jackson.databind.JsonNode dataNode)
      Ensures 'DATA' node is Array containing only valid Resource Objects or Resource Identifier Objects.
      static void ensurePrimaryDataValidObjectOrNull​(com.fasterxml.jackson.databind.JsonNode dataNode)
      Ensures 'DATA' node is a valid object, null or has JsonNode type NULL.
      static void ensureValidDocument​(com.fasterxml.jackson.databind.ObjectMapper mapper, com.fasterxml.jackson.databind.JsonNode resourceNode)
      Ensures document has at least one of 'DATA', 'ERRORS' or 'META' attributes.
      static void ensureValidResourceObjectArray​(com.fasterxml.jackson.databind.JsonNode dataNode)
      Ensures 'DATA' node is Array containing only valid Resource Objects.
      static boolean isArrayOfResourceIdentifierObjects​(com.fasterxml.jackson.databind.JsonNode dataNode)
      Returns true in case 'DATA' node has array of valid Resource Identifier Objects.
      static boolean isArrayOfResourceObjects​(com.fasterxml.jackson.databind.JsonNode dataNode)
      Returns true in case 'DATA' node has array of valid Resource Objects.
      static boolean isNotNullNode​(com.fasterxml.jackson.databind.JsonNode dataNode)
      Returns true in case 'DATA' node is not null and does not have JsonNode type NULL.
      static boolean isResourceIdentifierObject​(com.fasterxml.jackson.databind.JsonNode dataNode)
      Returns true in case node has 'ID' and 'TYPE' attributes.
      static boolean isResourceObject​(com.fasterxml.jackson.databind.JsonNode dataNode)
      Returns true in case 'DATA' node has 'ATTRIBUTES' and 'TYPE' attributes.
      static boolean isValidObject​(com.fasterxml.jackson.databind.JsonNode dataNode)
      Returns true in case 'DATA' node is valid Resource Object or Resource Identifier Object.
    • Method Detail

      • ensureValidDocument

        public static void ensureValidDocument​(com.fasterxml.jackson.databind.ObjectMapper mapper,
                                               com.fasterxml.jackson.databind.JsonNode resourceNode)
        Ensures document has at least one of 'DATA', 'ERRORS' or 'META' attributes.
        Parameters:
        resourceNode - resource node
        Throws:
        ResourceParseException - Maps error attribute into ResourceParseException if present.
        InvalidJsonApiResourceException - is thrown when node has none of the required attributes.
      • ensurePrimaryDataValidArray

        public static void ensurePrimaryDataValidArray​(com.fasterxml.jackson.databind.JsonNode dataNode)
        Ensures 'DATA' node is Array containing only valid Resource Objects or Resource Identifier Objects.
        Parameters:
        dataNode - array data node
        Throws:
        InvalidJsonApiResourceException - is thrown when 'DATA' node is not an array of valid resource objects, an array of valid resource identifier objects, or an empty array.
      • ensurePrimaryDataValidObjectOrNull

        public static void ensurePrimaryDataValidObjectOrNull​(com.fasterxml.jackson.databind.JsonNode dataNode)
        Ensures 'DATA' node is a valid object, null or has JsonNode type NULL.
        Parameters:
        dataNode - data node.
        Throws:
        InvalidJsonApiResourceException - is thrown when 'DATA' node is not valid object, null or null node.
      • ensureValidResourceObjectArray

        public static void ensureValidResourceObjectArray​(com.fasterxml.jackson.databind.JsonNode dataNode)
        Ensures 'DATA' node is Array containing only valid Resource Objects.
        Parameters:
        dataNode - resource object array data node
        Throws:
        InvalidJsonApiResourceException - is thrown when 'DATA' node is not an array of valid resource objects, or an empty array.
      • isNotNullNode

        public static boolean isNotNullNode​(com.fasterxml.jackson.databind.JsonNode dataNode)
        Returns true in case 'DATA' node is not null and does not have JsonNode type NULL.
        Parameters:
        dataNode - data node.
        Returns:
        false if node is null or is null node true node.
      • isValidObject

        public static boolean isValidObject​(com.fasterxml.jackson.databind.JsonNode dataNode)
        Returns true in case 'DATA' node is valid Resource Object or Resource Identifier Object.
        Parameters:
        dataNode - object data node
        Returns:
        true if node is valid primary data object, else false
      • isResourceIdentifierObject

        public static boolean isResourceIdentifierObject​(com.fasterxml.jackson.databind.JsonNode dataNode)
        Returns true in case node has 'ID' and 'TYPE' attributes.
        Parameters:
        dataNode - resource identifier object data node
        Returns:
        true if node has required attributes and all provided attributes are valid, else false
      • isResourceObject

        public static boolean isResourceObject​(com.fasterxml.jackson.databind.JsonNode dataNode)
        Returns true in case 'DATA' node has 'ATTRIBUTES' and 'TYPE' attributes.
        Parameters:
        dataNode - resource object data node
        Returns:
        true if node has required attributes and all provided attributes are valid, else false
      • isArrayOfResourceObjects

        public static boolean isArrayOfResourceObjects​(com.fasterxml.jackson.databind.JsonNode dataNode)
        Returns true in case 'DATA' node has array of valid Resource Objects.
        Parameters:
        dataNode - resource object array data node
        Returns:
        true if node is empty array or contains only valid Resource Objects
      • isArrayOfResourceIdentifierObjects

        public static boolean isArrayOfResourceIdentifierObjects​(com.fasterxml.jackson.databind.JsonNode dataNode)
        Returns true in case 'DATA' node has array of valid Resource Identifier Objects.
        Parameters:
        dataNode - resource identifier object array data node
        Returns:
        true if node is empty array or contains only valid Resource Identifier Objects