Package edu.byu.hbll.box.internal.util
Class JsonUtils
- java.lang.Object
-
- edu.byu.hbll.box.internal.util.JsonUtils
-
public class JsonUtils extends Object
Json utilities.
-
-
Constructor Summary
Constructors Constructor Description JsonUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
bind(com.fasterxml.jackson.databind.JsonNode node, Object object)
Binds the givenJsonNode
to the provided object.static void
bind(com.fasterxml.jackson.databind.JsonNode node, Map<String,com.fasterxml.jackson.databind.JsonNode> values)
Binds values in the map to the givenJsonNode
.static com.fasterxml.jackson.databind.JsonNode
deserialize(String value)
Deserializes the string to aJsonNode
.static com.fasterxml.jackson.databind.JsonNode
dotPath(com.fasterxml.jackson.databind.JsonNode node, String dotPath)
Return the foundJsonNode
after following the dot notation path.static boolean
matchesProjection(String field, Collection<String> fields)
Tests whether or not the given field is part of the field projection denoted by the given fields.static com.fasterxml.jackson.databind.JsonNode
project(com.fasterxml.jackson.databind.JsonNode node, Collection<String> fields)
Projects the given fields of the given node onto a new node.static String
serialize(Object document)
Serializes the document to a string.static com.fasterxml.jackson.databind.JsonNode
toJsonNode(Object value)
Converts an object to aJsonNode
.
-
-
-
Method Detail
-
bind
public static void bind(com.fasterxml.jackson.databind.JsonNode node, Map<String,com.fasterxml.jackson.databind.JsonNode> values)
Binds values in the map to the givenJsonNode
. The key in the map is the name of the variable in the node. The value in the map replaces the ${VARIABLE_NAME} in the node.- Parameters:
node
- the node to modifyvalues
- the values to bind to the node
-
bind
public static void bind(com.fasterxml.jackson.databind.JsonNode node, Object object)
Binds the givenJsonNode
to the provided object.- Parameters:
node
- the values to bindobject
- values are bound to this object
-
deserialize
public static com.fasterxml.jackson.databind.JsonNode deserialize(String value)
Deserializes the string to aJsonNode
.- Parameters:
value
- the string to deserialize- Returns:
- the deserialized node
-
dotPath
public static com.fasterxml.jackson.databind.JsonNode dotPath(com.fasterxml.jackson.databind.JsonNode node, String dotPath)
Return the foundJsonNode
after following the dot notation path.- Parameters:
node
- the subectdotPath
- the path- Returns:
- the found node or missing node if none found
-
serialize
public static String serialize(Object document)
Serializes the document to a string.- Parameters:
document
- the document to serialize.- Returns:
- the serialized string
-
toJsonNode
public static com.fasterxml.jackson.databind.JsonNode toJsonNode(Object value)
Converts an object to aJsonNode
.- Parameters:
value
- the object to convert- Returns:
- the resulting
JsonNode
-
project
public static com.fasterxml.jackson.databind.JsonNode project(com.fasterxml.jackson.databind.JsonNode node, Collection<String> fields)
Projects the given fields of the given node onto a new node. An empty fields projects the entire document.Note: projection follows MongoDB's projection pattern (https://docs.mongodb.com/manual/tutorial/project-fields-from-query-results/). The projection is only applied to child nodes of objects. Arrays or nested arrays are iterated over and projection picks up again when objects are found. Primitive values that are not part of a terminal projection are removed.
- Parameters:
node
- the subject of the projectionfields
- dot-notated fields denoting what should be projected- Returns:
- the projected node
-
matchesProjection
public static boolean matchesProjection(String field, Collection<String> fields)
Tests whether or not the given field is part of the field projection denoted by the given fields.Note: projection follows MongoDB's projection pattern (https://docs.mongodb.com/manual/tutorial/project-fields-from-query-results/).
- Parameters:
field
- the field to testfields
- the projection- Returns:
- if the field is part of the projection
-
-