Package com.github.jasminb.jsonapi
Class ValidationUtils
- java.lang.Object
-
- com.github.jasminb.jsonapi.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 voidensurePrimaryDataValidArray(com.fasterxml.jackson.databind.JsonNode dataNode)Ensures 'DATA' node is Array containing only valid Resource Objects or Resource Identifier Objects.static voidensurePrimaryDataValidObjectOrNull(com.fasterxml.jackson.databind.JsonNode dataNode)Ensures 'DATA' node is a valid object, null or has JsonNode type NULL.static voidensureValidDocument(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 voidensureValidResourceObjectArray(com.fasterxml.jackson.databind.JsonNode dataNode)Ensures 'DATA' node is Array containing only valid Resource Objects.static booleanisArrayOfResourceIdentifierObjects(com.fasterxml.jackson.databind.JsonNode dataNode)Returnstruein case 'DATA' node has array of valid Resource Identifier Objects.static booleanisArrayOfResourceObjects(com.fasterxml.jackson.databind.JsonNode dataNode)Returnstruein case 'DATA' node has array of valid Resource Objects.static booleanisNotNullNode(com.fasterxml.jackson.databind.JsonNode dataNode)Returnstruein case 'DATA' node is not null and does not have JsonNode type NULL.static booleanisResourceIdentifierObject(com.fasterxml.jackson.databind.JsonNode dataNode)Returnstruein case node has 'ID' and 'TYPE' attributes.static booleanisResourceObject(com.fasterxml.jackson.databind.JsonNode dataNode)Returnstruein case 'DATA' node has 'ATTRIBUTES' and 'TYPE' attributes.static booleanisValidObject(com.fasterxml.jackson.databind.JsonNode dataNode)Returnstruein 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)
Returnstruein case 'DATA' node is not null and does not have JsonNode type NULL.- Parameters:
dataNode- data node.- Returns:
falseif node is null or is null nodetruenode.
-
isValidObject
public static boolean isValidObject(com.fasterxml.jackson.databind.JsonNode dataNode)
Returnstruein case 'DATA' node is valid Resource Object or Resource Identifier Object.- Parameters:
dataNode- object data node- Returns:
trueif node is valid primary data object, elsefalse
-
isResourceIdentifierObject
public static boolean isResourceIdentifierObject(com.fasterxml.jackson.databind.JsonNode dataNode)
Returnstruein case node has 'ID' and 'TYPE' attributes.- Parameters:
dataNode- resource identifier object data node- Returns:
trueif node has required attributes and all provided attributes are valid, elsefalse
-
isResourceObject
public static boolean isResourceObject(com.fasterxml.jackson.databind.JsonNode dataNode)
Returnstruein case 'DATA' node has 'ATTRIBUTES' and 'TYPE' attributes.- Parameters:
dataNode- resource object data node- Returns:
trueif node has required attributes and all provided attributes are valid, elsefalse
-
isArrayOfResourceObjects
public static boolean isArrayOfResourceObjects(com.fasterxml.jackson.databind.JsonNode dataNode)
Returnstruein case 'DATA' node has array of valid Resource Objects.- Parameters:
dataNode- resource object array data node- Returns:
trueif node is empty array or contains only valid Resource Objects
-
isArrayOfResourceIdentifierObjects
public static boolean isArrayOfResourceIdentifierObjects(com.fasterxml.jackson.databind.JsonNode dataNode)
Returnstruein case 'DATA' node has array of valid Resource Identifier Objects.- Parameters:
dataNode- resource identifier object array data node- Returns:
trueif node is empty array or contains only valid Resource Identifier Objects
-
-