Package io.stargate.sdk.utils
Class JsonUtils
java.lang.Object
io.stargate.sdk.utils.JsonUtils
Custom implementation of serialization : faster + no jackson dependency
- Author:
- Cedrick Lunven (@clunven)
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> StringcollectionAsJson(Collection<T> pCollec) Serialize a collection of object as Json.static <T> TconvertValue(Object bean, Class<T> clazz) Jackson deserialization.static <T> TconvertValueForDataApi(Object bean, Class<T> clazz) Jackson deserialization.static StringescapeJson(String value) Code is built based on https://github.com/fangyidong/json-simple/blob/master/src/main/java/org/json/simple/JSONValue.java by FangYidong fangyidong@yahoo.com.cn THANK YOU ! ff4j core needs to stay with no dependency.static com.fasterxml.jackson.databind.ObjectMapperBuilding the data api specific object mapper.static com.fasterxml.jackson.databind.ObjectMapperAccess the singletong ObjectMapper.static <K,V> String Serialize a map of objects as Json.static StringTransform object as a String.static StringTransform object as a String.static <T> TunmarshallBean(String body, Class<T> ref) Load body as expected object.static <T> TunmarshallBeanForDataApi(String body, Class<T> ref) Load body as expected object.static <T> TunmarshallType(String body, com.fasterxml.jackson.core.type.TypeReference<T> ref) Load body as expected object.static <T> TunmarshallTypeForDataApi(String body, com.fasterxml.jackson.core.type.TypeReference<T> ref) Load body as expected object.static StringvalueAsJson(Object value) Target primitive displayed as JSON.
-
Method Details
-
getDataApiObjectMapper
public static com.fasterxml.jackson.databind.ObjectMapper getDataApiObjectMapper()Building the data api specific object mapper.- Returns:
- object mapper.
-
escapeJson
Code is built based on https://github.com/fangyidong/json-simple/blob/master/src/main/java/org/json/simple/JSONValue.java by FangYidong fangyidong@yahoo.com.cn THANK YOU ! ff4j core needs to stay with no dependency. The following characters are reserved characters and can not be used in JSON and must be properly escaped to be used in strings. - Backspace to be replaced with \b - Form feed to be replaced with \f - Newline to be replaced with \n - Carriage return to be replaced with \r - Tab to be replaced with \t - Double quote to be replaced with \" - Backslash to be replaced with \\- Parameters:
value- string to be escaped- Returns:
- escaped JSON
-
valueAsJson
Target primitive displayed as JSON.- Parameters:
value- object value- Returns:
- target json expression
-
collectionAsJson
Serialize a collection of object as Json. Element should eventually overridetoString()to produce JSON.- Type Parameters:
T- T- Parameters:
pCollec- input collection- Returns:
- collection as String
-
mapAsJson
Serialize a map of objects as Json. Elements should overridetoString()to produce JSON.- Type Parameters:
K- KV- V- Parameters:
pMap- target properties- Returns:
- target json expression
-
getObjectMapper
public static com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()Access the singletong ObjectMapper.- Returns:
- object mapper
-
marshall
Transform object as a String.- Parameters:
o- object to be serialized.- Returns:
- body as String
-
marshallForDataApi
Transform object as a String.- Parameters:
o- object to be serialized.- Returns:
- body as String
-
convertValue
Jackson deserialization.- Type Parameters:
T- current type- Parameters:
bean- current beamclazz- target class- Returns:
- serialized
-
convertValueForDataApi
Jackson deserialization.- Type Parameters:
T- current type- Parameters:
bean- current beamclazz- target class- Returns:
- serialized
-
unmarshallType
public static <T> T unmarshallType(String body, com.fasterxml.jackson.core.type.TypeReference<T> ref) Load body as expected object.- Type Parameters:
T- parameter- Parameters:
body- response body as Stringref- type Reference to map the result- Returns:
- expected object
-
unmarshallTypeForDataApi
public static <T> T unmarshallTypeForDataApi(String body, com.fasterxml.jackson.core.type.TypeReference<T> ref) Load body as expected object.- Type Parameters:
T- parameter- Parameters:
body- response body as Stringref- type Reference to map the result- Returns:
- expected object
-
unmarshallBean
Load body as expected object.- Type Parameters:
T- parameter- Parameters:
body- response body as Stringref- type Reference to map the result- Returns:
- expected objects
-
unmarshallBeanForDataApi
Load body as expected object.- Type Parameters:
T- parameter- Parameters:
body- response body as Stringref- type Reference to map the result- Returns:
- expected objects
-