Class 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 Detail

      • 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 class
        json -
        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 reference
        json -
        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
      • convert

        public <T> T convert​(Object fromValue,
                             Class<T> toType)
        Converts Map like objects into instance of class specified.
        Parameters:
        fromValue - object similar to java Map.
        toType - object is converted into an instance of this class
        Returns: