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); } } }