Package com.identity4j.util.json
Class JsonMapperService
- java.lang.Object
-
- com.identity4j.util.json.JsonMapperService
-
public class JsonMapperService extends Object
This singleton class is responsible for handling serialization/deserialization of POJOs into JSON.
- Here it encapsulates trivial configuration.
- It also handles custom POJO setting from HttpResponseData.
- Author:
- gaurav
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> Tconvert(Object fromValue, Class<T> toType)Converts Map like objects into instance of class specified.static JsonMapperServicegetInstance()StringgetJson(Object object)Converts a Java object into json.ObjectgetJsonProperty(String json, String property)Fetches a property from a json string.<T> TgetObject(com.fasterxml.jackson.core.type.TypeReference<T> typeReference, String json)Maps a json String to Java object specified by TypeReference.<T> TgetObject(Class<T> clazz, String json)Maps a json String to Java object.
-
-
-
Method Detail
-
getInstance
public static JsonMapperService getInstance()
-
getObject
public <T> T getObject(Class<T> clazz, String json)
Maps a json String to Java object.- Parameters:
clazz- json object is mapped to this classjson-- Returns:
- mapped java object
-
getObject
public <T> T getObject(com.fasterxml.jackson.core.type.TypeReference<T> typeReference, String json)Maps a json String to Java object specified by TypeReference.- Parameters:
typeReference- json object is mapped to this type referencejson-- Returns:
- mapped java object
-
getJson
public String getJson(Object object) throws IOException
Converts a Java object into json.- Parameters:
object-- Returns:
- converted json string
- Throws:
IOException
-
getJsonProperty
public Object getJsonProperty(String json, String property)
Fetches a property from a json string. It converts the json into a java Map instance. Hence we can fetch only first level properties only.- Parameters:
json-property-- Returns:
- property value
-
-