parent
a801724b75
commit
db6c7d402f
@ -0,0 +1,22 @@
|
||||
package cn.teammodel.utils;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
public class JsonUtil {
|
||||
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
/**
|
||||
* Converts an object to a JSON string.
|
||||
*
|
||||
* @param obj The object to be converted.
|
||||
* @return The JSON string representation of the object.
|
||||
*/
|
||||
public static String convertToJson(Object obj) {
|
||||
try {
|
||||
return objectMapper.writeValueAsString(obj);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException("Failed to convert object to JSON", e);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue