Add toObject method and test

This commit is contained in:
Darin Kelkhoff
2021-11-28 21:40:37 -06:00
parent e399b9aa4f
commit 1cde633c1b
2 changed files with 50 additions and 1 deletions

View File

@ -1,6 +1,7 @@
package com.kingsrook.qqq.backend.core.utils;
import java.io.IOException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
@ -63,6 +64,17 @@ public class JsonUtils
}
/*******************************************************************************
**
*******************************************************************************/
public static <T> T toObject(String json, Class<T> targetClass) throws IOException
{
ObjectMapper objectMapper = newObjectMapper();
T t = objectMapper.reader().readValue(json, targetClass);
return t;
}
/*******************************************************************************
**