Package com.bazaarvoice.jolt
Class JsonUtils
java.lang.Object
com.bazaarvoice.jolt.JsonUtils
Static method convenience wrappers for a JsonUtil configured with a minimal ObjectMapper.
The ObjectMapper use is configured to :
Allow comments in the JSON strings,
Hydrates all JSON Maps into LinkedHashMaps.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionclasspathToList
(String classPath) classpathToMap
(String classPath) static Object
classpathToObject
(String classPath) static <T> T
classpathToType
(String classPath, com.fasterxml.jackson.core.type.TypeReference<T> typeRef) static <T> T
classpathToType
(String classPath, Class<T> aClass) static Object
Makes a deep copy of a Mapinvalid input: '<'String, Object> object by converting it to a String and then back onto stock JSON objects.static JsonUtil
customJsonUtil
(com.fasterxml.jackson.databind.ObjectMapper mapper) Construct a JsonUtil with a Jackson ObjectMapper that has been preconfigured with custom Modules or Mixins.filepathToList
(String filePath) filepathToMap
(String filePath) static Object
filepathToObject
(String filePath) static <T> T
fileToType
(String filePath, com.fasterxml.jackson.core.type.TypeReference<T> typeRef) static <T> T
fileToType
(String filePath, Class<T> aClass) static JsonUtil
Utility for test classes, so that they can inline json in a test class.static <T> T
jsonTo
(InputStream in, com.fasterxml.jackson.core.type.TypeReference<T> typeRef) Deprecated.static <T> T
Deprecated.jsonToList
(String json) jsonToList
(String json, String charset) jsonToMap
(InputStream in) static Object
static Object
jsonToObject
(String json) static Object
jsonToObject
(String json, String charset) static <T> T
Deprecated.static void
removeRecursive
(Object json, String keyToRemove) Deprecated.static <T> T
streamToType
(InputStream in, com.fasterxml.jackson.core.type.TypeReference<T> typeRef) static <T> T
streamToType
(InputStream in, Class<T> aClass) static <T> T
stringToType
(String json, com.fasterxml.jackson.core.type.TypeReference<T> typeRef) static <T> T
stringToType
(String json, Class<T> aClass) static String
toJsonString
(Object obj) static String
toPrettyJsonString
(Object obj)
-
Field Details
-
util
-
-
Constructor Details
-
JsonUtils
public JsonUtils()
-
-
Method Details
-
customJsonUtil
Construct a JsonUtil with a Jackson ObjectMapper that has been preconfigured with custom Modules or Mixins. -
removeRecursive
Deprecated.Removes a key recursively from anywhere in a JSON document. NOTE: mutates its input. Deprecated: use JoltUtils instead- Parameters:
json
- the Jackson Object version of the JSON document (contents changed by this call)keyToRemove
- the key to remove from the document
-
javason
Utility for test classes, so that they can inline json in a test class. Does a character level replacement of apostrophe (') with double quote ("). This means you can express a snippit of JSON without having to forward slash escape everything. This is character based, so don't have any apostrophes (') in your test data.- Parameters:
javason
- JSON-ish string you want to turn into Maps-of-Maps- Returns:
- Maps-of-Maps
-
getDefaultJsonUtil
-
jsonToObject
-
jsonToObject
-
jsonToObject
-
jsonToMap
-
jsonToMap
-
jsonToMap
-
jsonToList
-
jsonToList
-
jsonToList
-
filepathToObject
-
filepathToMap
-
filepathToList
-
classpathToObject
-
classpathToMap
-
classpathToList
-
classpathToType
public static <T> T classpathToType(String classPath, com.fasterxml.jackson.core.type.TypeReference<T> typeRef) -
classpathToType
-
stringToType
public static <T> T stringToType(String json, com.fasterxml.jackson.core.type.TypeReference<T> typeRef) -
stringToType
-
fileToType
public static <T> T fileToType(String filePath, com.fasterxml.jackson.core.type.TypeReference<T> typeRef) -
fileToType
-
streamToType
public static <T> T streamToType(InputStream in, com.fasterxml.jackson.core.type.TypeReference<T> typeRef) -
streamToType
-
jsonTo
@Deprecated public static <T> T jsonTo(String json, com.fasterxml.jackson.core.type.TypeReference<T> typeRef) Deprecated.Use the stringToType method instead. -
jsonTo
@Deprecated public static <T> T jsonTo(InputStream in, com.fasterxml.jackson.core.type.TypeReference<T> typeRef) Deprecated.Use the streamToType method instead. -
toJsonString
-
toPrettyJsonString
-
cloneJson
Makes a deep copy of a Mapinvalid input: '<'String, Object> object by converting it to a String and then back onto stock JSON objects.- Parameters:
obj
- object tree to copy- Returns:
- deep copy of the incoming obj
-