|
|
@@ -1,59 +0,0 @@
|
|
|
-package com.zhongshu.card.server.core.service.oss;
|
|
|
-
|
|
|
-import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
-import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.stereotype.Component;
|
|
|
-
|
|
|
-@Component
|
|
|
-class JsonHelperOSS {
|
|
|
-
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private ObjectMapper objectMapper;
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 转换到json字符串
|
|
|
- *
|
|
|
- * @param object
|
|
|
- * @return
|
|
|
- * @throws Exception
|
|
|
- */
|
|
|
- public String toJson(Object object, boolean format) {
|
|
|
- try {
|
|
|
- if (format) {
|
|
|
- return objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(object);
|
|
|
- } else {
|
|
|
- return objectMapper.writeValueAsString(object);
|
|
|
- }
|
|
|
- } catch (JsonProcessingException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 转换到json字符串
|
|
|
- *
|
|
|
- * @param object
|
|
|
- * @return
|
|
|
- */
|
|
|
- public String toJson(Object object) {
|
|
|
- return toJson(object, false);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 转换为对象
|
|
|
- *
|
|
|
- * @param json
|
|
|
- * @param cls
|
|
|
- * @return
|
|
|
- * @throws Exception
|
|
|
- */
|
|
|
- public <T> T toObject(String json, Class<T> cls) throws Exception {
|
|
|
- return objectMapper.readValue(json, cls);
|
|
|
- }
|
|
|
-}
|