I wrote a Generic method which works fine converting any Json object to Generic Object.
public <T> T convertJsontoObject (String jsonObj, Class<T> any Type)
throws JsonMappingException, JsonProcessingException
{
ObjectMapper objectMap = new ObjectMapper();
return objectMap.readValue(jsonObj, any Type);
}
But has an issue while converting the Generic Object type to JSON format with the below code format. Would someone help me or guide me with related code.. I am not sure how to retain an Object from Generic class type as the method doesn't support for generic and I want to have a Generic method to perform the conversions....
public <T> String convertObjectToJson(Class<T> anyType)
{ String jsonStringObj = "";
try { jsonStringObj = new
ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(anyType);}
}