public final class JsonHandler extends Object
Modifier and Type | Method and Description |
---|---|
static Map.Entry<String,com.fasterxml.jackson.databind.JsonNode> |
checkLaxUnicity(String nodeName,
com.fasterxml.jackson.databind.JsonNode node)
node should have only one property ; simple value is allowed
|
static void |
checkNullOrEmpty(String message,
com.fasterxml.jackson.databind.JsonNode... nodes)
Check if JsonNodes are not null and not empty
|
static Map.Entry<String,com.fasterxml.jackson.databind.JsonNode> |
checkUnicity(String nodeName,
com.fasterxml.jackson.databind.JsonNode node)
node should have only one property
|
static com.fasterxml.jackson.databind.node.ArrayNode |
createArrayNode() |
static com.fasterxml.jackson.core.JsonGenerator |
createJsonGenerator(OutputStream os)
Creates a JSON generator for low-level json stream creation
|
static com.fasterxml.jackson.databind.node.ObjectNode |
createObjectNode() |
static com.fasterxml.jackson.databind.node.JsonNodeFactory |
getFactory() |
static com.fasterxml.jackson.databind.JsonNode |
getFromBytes(byte[] value) |
static com.fasterxml.jackson.databind.JsonNode |
getFromFile(File file) |
static <T> T |
getFromFile(File file,
Class<T> clasz) |
static <T> T |
getFromFileAsTypeRefence(File file,
com.fasterxml.jackson.core.type.TypeReference valueTypeRef) |
static <T> T |
getFromFileLowerCamelCase(File file,
Class<T> clasz) |
static com.fasterxml.jackson.databind.JsonNode |
getFromInputStream(InputStream stream)
getFromInputStream, get JsonNode from stream
|
static <T> T |
getFromInputStream(InputStream inputStream,
Class<T> clasz) |
static com.fasterxml.jackson.databind.JsonNode |
getFromInputStream(InputStream stream1,
InputStream stream2)
getFromInputStream, get merged JsonNode from streams
|
static <T> T |
getFromJsonNode(com.fasterxml.jackson.databind.JsonNode jsonNode,
Class<T> clasz) |
static <T> T |
getFromJsonNodeLowerCamelCase(com.fasterxml.jackson.databind.JsonNode jsonNode,
Class<T> clasz) |
static com.fasterxml.jackson.databind.JsonNode |
getFromString(String value) |
static <T> T |
getFromString(String value,
Class<T> clasz) |
static <T> T |
getFromString(String value,
Class<T> clasz,
Class<?> parameterClazz) |
static <T> T |
getFromStringAsTypeRefence(String value,
com.fasterxml.jackson.core.type.TypeReference<T> clasz) |
static <T> T |
getFromStringLowerCamelCase(String value,
Class<T> clasz) |
static Map<String,Object> |
getMapFromInputStream(InputStream inputStream) |
static <T> Map<String,T> |
getMapFromInputStream(InputStream inputStream,
Class<T> parameterClazz)
transform an inputStream into a {Map
|
static Map<String,Object> |
getMapFromString(String value) |
static Map<String,String> |
getMapStringFromString(String value) |
static com.fasterxml.jackson.databind.JsonNode |
getNodeByPath(com.fasterxml.jackson.databind.JsonNode node,
String fieldPath,
boolean deepCopy)
Find a node with the given path
|
static com.fasterxml.jackson.databind.JsonNode |
getParentNodeByPath(com.fasterxml.jackson.databind.JsonNode node,
String fieldPath,
boolean deepCopy)
Find a parent of the node with the given path
|
static com.fasterxml.jackson.databind.node.ArrayNode |
getSubArrayNode(com.fasterxml.jackson.databind.node.ArrayNode array,
int offset,
int limit)
From one ArrayNode, get a new ArrayNode from offset to limit items
|
static String |
prettyPrint(Object object) |
static void |
setNodeInPath(com.fasterxml.jackson.databind.node.ObjectNode node,
String nodePath,
com.fasterxml.jackson.databind.JsonNode value,
boolean canCreate)
Set a value in a node defined by the given path.
|
static List |
toArrayList(com.fasterxml.jackson.databind.node.ArrayNode arrayNode)
transform an
ArrayNode (JSON Array) to an ArrayList |
static com.fasterxml.jackson.databind.JsonNode |
toJsonNode(Object object) |
static String |
unprettyPrint(Object object) |
static boolean |
validate(String value) |
static void |
writeAsFile(Object object,
File file) |
static void |
writeAsOutputStream(Object object,
OutputStream outputStream) |
static String |
writeAsString(Object object) |
static InputStream |
writeToInpustream(Object object) |
public static final com.fasterxml.jackson.databind.node.JsonNodeFactory getFactory()
public static final com.fasterxml.jackson.databind.node.ObjectNode createObjectNode()
public static final com.fasterxml.jackson.databind.node.ArrayNode createArrayNode()
public static final com.fasterxml.jackson.databind.JsonNode getFromString(String value) throws InvalidParseOperationException
value
- in format String to transformInvalidParseOperationException
- if parse JsonNode object exception occurredpublic static final boolean validate(String value) throws InvalidParseOperationException
value
- in format String to transformInvalidParseOperationException
- if parse JsonNode object exception occurredpublic static final com.fasterxml.jackson.core.JsonGenerator createJsonGenerator(OutputStream os) throws IOException
os
- the output streamIOException
public static final com.fasterxml.jackson.databind.JsonNode getFromFile(File file) throws InvalidParseOperationException
file
- to transformInvalidParseOperationException
- if parse JsonNode object exception occurredpublic static final com.fasterxml.jackson.databind.JsonNode getFromInputStream(InputStream stream) throws InvalidParseOperationException
stream
- to transformInvalidParseOperationException
- if parse JsonNode object exception occurredpublic static final com.fasterxml.jackson.databind.JsonNode getFromInputStream(InputStream stream1, InputStream stream2) throws InvalidParseOperationException
stream1
- to transformstream2
- to transform and merge withInvalidParseOperationException
- if parse JsonNode object exception occurredpublic static final <T> T getFromString(String value, Class<T> clasz) throws InvalidParseOperationException
value
- to transformclasz
- the instance of target classInvalidParseOperationException
- if parse JsonNode object exception occurredpublic static final <T> T getFromStringAsTypeRefence(String value, com.fasterxml.jackson.core.type.TypeReference<T> clasz) throws InvalidParseOperationException
value
- to transformclasz
- the instance of target classInvalidParseOperationException
- if parse JsonNode object exception occurredpublic static final <T> T getFromString(String value, Class<T> clasz, Class<?> parameterClazz) throws InvalidParseOperationException
value
- in format String to transformclasz
- the instance of target classparameterClazz
- the the target class template parametersInvalidParseOperationException
- if parse JsonNode object exception occurredpublic static final <T> T getFromStringLowerCamelCase(String value, Class<T> clasz) throws InvalidParseOperationException
value
- to transformclasz
- the instance of target classInvalidParseOperationException
- if parse JsonNode object exception occurredpublic static final com.fasterxml.jackson.databind.JsonNode getFromBytes(byte[] value) throws InvalidParseOperationException
value
- in format byte to transformInvalidParseOperationException
- if parse JsonNode object exception occurredpublic static final <T> T getFromFile(File file, Class<T> clasz) throws InvalidParseOperationException
file
- to transformclasz
- the instance of target classInvalidParseOperationException
- if parse JsonNode object exception occurredpublic static final <T> T getFromFileAsTypeRefence(File file, com.fasterxml.jackson.core.type.TypeReference valueTypeRef) throws InvalidParseOperationException
file
- to transformvalueTypeRef
- the type reference of target classInvalidParseOperationException
- if parse JsonNode object exception occurredpublic static final <T> T getFromFileLowerCamelCase(File file, Class<T> clasz) throws InvalidParseOperationException
file
- to transformclasz
- the instance of target classInvalidParseOperationException
- if parse JsonNode object exception occurredpublic static final <T> T getFromJsonNode(com.fasterxml.jackson.databind.JsonNode jsonNode, Class<T> clasz) throws InvalidParseOperationException
jsonNode
- the json object to transformclasz
- the instance of target classInvalidParseOperationException
- if parse JsonNode object exception occurredpublic static final <T> T getFromJsonNodeLowerCamelCase(com.fasterxml.jackson.databind.JsonNode jsonNode, Class<T> clasz) throws InvalidParseOperationException
jsonNode
- the json object to getclasz
- the instance of target classInvalidParseOperationException
- if parse JsonNode object exception occurredpublic static final com.fasterxml.jackson.databind.JsonNode toJsonNode(Object object) throws InvalidParseOperationException
object
- to transformInvalidParseOperationException
- if parse JsonNode object exception occurredpublic static final String writeAsString(Object object) throws InvalidParseOperationException
object
- to transformInvalidParseOperationException
- if parse JsonNode object exception occurredpublic static String prettyPrint(Object object)
object
- to writepublic static String unprettyPrint(Object object)
object
- to transformpublic static final void writeAsFile(Object object, File file) throws InvalidParseOperationException
object
- to writefile
- to write objectInvalidParseOperationException
- if parse JsonNode object exception occurredpublic static final void writeAsOutputStream(Object object, OutputStream outputStream) throws InvalidParseOperationException
object
- to writeoutputStream
- the output streamInvalidParseOperationException
- if parse JsonNode object exception occurredpublic static final InputStream writeToInpustream(Object object) throws InvalidParseOperationException
object
- InvalidParseOperationException
public static final void checkNullOrEmpty(String message, com.fasterxml.jackson.databind.JsonNode... nodes)
message
- default message within exceptionnodes
- to checkIllegalArgumentException
- if nodes are null or emptypublic static final Map.Entry<String,com.fasterxml.jackson.databind.JsonNode> checkUnicity(String nodeName, com.fasterxml.jackson.databind.JsonNode node) throws InvalidParseOperationException
nodeName
- name to print in case of errornode
- to checkInvalidParseOperationException
- if parse JsonNode object exception occurredpublic static final Map.Entry<String,com.fasterxml.jackson.databind.JsonNode> checkLaxUnicity(String nodeName, com.fasterxml.jackson.databind.JsonNode node) throws InvalidParseOperationException
nodeName
- name to print in case of errornode
- to checkInvalidParseOperationException
- if parse JsonNode object exception occurredpublic static final Map<String,Object> getMapFromString(String value) throws InvalidParseOperationException
value
- to transformInvalidParseOperationException
- if parse JsonNode object exception occurredpublic static final Map<String,String> getMapStringFromString(String value) throws InvalidParseOperationException
value
- to transformInvalidParseOperationException
- if parse JsonNode object exception occurredpublic static final Map<String,Object> getMapFromInputStream(InputStream inputStream) throws InvalidParseOperationException
inputStream
- to transformInvalidParseOperationException
- if parse JsonNode object exception occurredpublic static final <T> Map<String,T> getMapFromInputStream(InputStream inputStream, Class<T> parameterClazz) throws InvalidParseOperationException
T
- the class templateinputStream
- to transformparameterClazz
- type of the value on the MapInvalidParseOperationException
- if parse JsonNode object exception occurredpublic static final <T> T getFromInputStream(InputStream inputStream, Class<T> clasz) throws InvalidParseOperationException
inputStream
- to transformclasz
- the instance of target classInvalidParseOperationException
- if parse JsonNode object exception occurredpublic static com.fasterxml.jackson.databind.node.ArrayNode getSubArrayNode(com.fasterxml.jackson.databind.node.ArrayNode array, int offset, int limit)
array
- to get node dataoffset
- of array to getlimit
- of array to getpublic static com.fasterxml.jackson.databind.JsonNode getNodeByPath(com.fasterxml.jackson.databind.JsonNode node, String fieldPath, boolean deepCopy)
node
- the parent Node within the search must be performedfieldPath
- the field to find in the root. use '.' to get sub-node (ex: parent.child.subNodeName)deepCopy
- if true, the returned node is a copy of the matching node, else return the original onepublic static com.fasterxml.jackson.databind.JsonNode getParentNodeByPath(com.fasterxml.jackson.databind.JsonNode node, String fieldPath, boolean deepCopy)
node
- the root Node within the search must be performedfieldPath
- the field to find in the root. use '.' to get sub-node (ex: ["parent","child","subNodeName"])deepCopy
- if true, the returned node is a copy of the matching node, else return the original onepublic static void setNodeInPath(com.fasterxml.jackson.databind.node.ObjectNode node, String nodePath, com.fasterxml.jackson.databind.JsonNode value, boolean canCreate) throws InvalidParseOperationException
node
- the rootNodenodePath
- the path of the node that must be updated/createdvalue
- The new value of the nodecanCreate
- true if missing nodes muse be created. Else an error was thrown for missing nodesInvalidParseOperationException
Copyright © 2018 Vitam. All rights reserved.