Package com.bazaarvoice.jolt
Class JsonUtilImpl
java.lang.Object
com.bazaarvoice.jolt.JsonUtilImpl
- All Implemented Interfaces:
JsonUtil
Implementation of JsonUtil that allows the user to provide a configured
Jackson ObjectMapper.
All IOExceptions are caught, wrapped with context, and rethrown as RuntimeExceptions.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
private final com.fasterxml.jackson.databind.ObjectMapper
private final com.fasterxml.jackson.databind.ObjectWriter
-
Constructor Summary
ConstructorsConstructorDescriptionJsonUtilImpl
(com.fasterxml.jackson.databind.ObjectMapper objectMapper) By allowing the user to provide an ObjectMapper, it can be configured with knowledge of how to marshall and un-marshall your domain objects. -
Method Summary
Modifier and TypeMethodDescriptionclasspathToList
(String classPath) classpathToMap
(String classPath) classpathToObject
(String classPath) <T> T
classpathToType
(String classPath, com.fasterxml.jackson.core.type.TypeReference<T> typeRef) <T> T
classpathToType
(String classPath, Class<T> aClass) 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 void
configureStockJoltObjectMapper
(com.fasterxml.jackson.databind.ObjectMapper objectMapper) filepathToList
(String filePath) filepathToMap
(String filePath) filepathToObject
(String filePath) <T> T
fileToType
(String filePath, com.fasterxml.jackson.core.type.TypeReference<T> typeRef) <T> T
fileToType
(String filePath, Class<T> aClass) <T> T
jsonTo
(InputStream in, com.fasterxml.jackson.core.type.TypeReference<T> typeRef) Deprecated.<T> T
Deprecated.jsonToList
(String json) jsonToList
(String json, String charset) jsonToMap
(InputStream in) jsonToObject
(String json) jsonToObject
(String json, String charset) <T> T
streamToType
(InputStream in, com.fasterxml.jackson.core.type.TypeReference<T> typeRef) <T> T
streamToType
(InputStream in, Class<T> aClass) <T> T
stringToType
(String json, com.fasterxml.jackson.core.type.TypeReference<T> typeRef) <T> T
stringToType
(String json, Class<T> aClass) toJsonString
(Object obj) toPrettyJsonString
(Object obj)
-
Field Details
-
objectMapper
private final com.fasterxml.jackson.databind.ObjectMapper objectMapper -
prettyPrintWriter
private final com.fasterxml.jackson.databind.ObjectWriter prettyPrintWriter -
DEFAULT_ENCODING_UTF_8
- See Also:
-
mapTypeReference
-
listTypeReference
-
-
Constructor Details
-
JsonUtilImpl
public JsonUtilImpl(com.fasterxml.jackson.databind.ObjectMapper objectMapper) By allowing the user to provide an ObjectMapper, it can be configured with knowledge of how to marshall and un-marshall your domain objects.- Parameters:
objectMapper
- a configured Jackson ObjectMapper
-
JsonUtilImpl
public JsonUtilImpl()
-
-
Method Details
-
configureStockJoltObjectMapper
public static void configureStockJoltObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper) -
jsonToObject
- Specified by:
jsonToObject
in interfaceJsonUtil
-
jsonToObject
- Specified by:
jsonToObject
in interfaceJsonUtil
-
jsonToObject
- Specified by:
jsonToObject
in interfaceJsonUtil
-
jsonToMap
-
jsonToMap
-
jsonToMap
-
jsonToList
- Specified by:
jsonToList
in interfaceJsonUtil
-
jsonToList
- Specified by:
jsonToList
in interfaceJsonUtil
-
jsonToList
- Specified by:
jsonToList
in interfaceJsonUtil
-
filepathToObject
- Specified by:
filepathToObject
in interfaceJsonUtil
-
filepathToMap
- Specified by:
filepathToMap
in interfaceJsonUtil
-
filepathToList
- Specified by:
filepathToList
in interfaceJsonUtil
-
classpathToObject
- Specified by:
classpathToObject
in interfaceJsonUtil
-
classpathToMap
- Specified by:
classpathToMap
in interfaceJsonUtil
-
classpathToList
- Specified by:
classpathToList
in interfaceJsonUtil
-
jsonTo
@Deprecated public <T> T jsonTo(InputStream in, com.fasterxml.jackson.core.type.TypeReference<T> typeRef) Deprecated.Description copied from interface:JsonUtil
Use the streamToType method instead. -
jsonTo
@Deprecated public <T> T jsonTo(String json, com.fasterxml.jackson.core.type.TypeReference<T> typeRef) Deprecated.Description copied from interface:JsonUtil
Use the stringToType method instead. -
stringToType
- Specified by:
stringToType
in interfaceJsonUtil
-
stringToType
- Specified by:
stringToType
in interfaceJsonUtil
-
classpathToType
public <T> T classpathToType(String classPath, com.fasterxml.jackson.core.type.TypeReference<T> typeRef) - Specified by:
classpathToType
in interfaceJsonUtil
-
classpathToType
- Specified by:
classpathToType
in interfaceJsonUtil
-
fileToType
- Specified by:
fileToType
in interfaceJsonUtil
-
fileToType
- Specified by:
fileToType
in interfaceJsonUtil
-
streamToType
- Specified by:
streamToType
in interfaceJsonUtil
-
streamToType
- Specified by:
streamToType
in interfaceJsonUtil
-
toJsonString
- Specified by:
toJsonString
in interfaceJsonUtil
-
toPrettyJsonString
- Specified by:
toPrettyJsonString
in interfaceJsonUtil
-
cloneJson
Description copied from interface:JsonUtil
Makes a deep copy of a Mapinvalid input: '<'String, Object> object by converting it to a String and then back onto stock JSON objects. Leverages Serialization
-