You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
680 B
23 lines
680 B
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);
|
|
}
|
|
}
|
|
}
|