mirror of
https://github.com/zongzibinbin/MallChat.git
synced 2026-03-14 14:13:42 +08:00
feat:
1.搭建分布式事务框架 2.项目引入rocketmq实现集群广播
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
package com.abin.mallchat.utils;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Author: <a href="https://github.com/zongzibinbin">abin</a>
|
||||
* Date: 2023-04-25
|
||||
*/
|
||||
public class JsonUtils {
|
||||
private static final ObjectMapper jsonMapper = new ObjectMapper();
|
||||
|
||||
public static <T> T toObj(String str, Class<T> clz) {
|
||||
try {
|
||||
return jsonMapper.readValue(str, clz);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new UnsupportedOperationException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T toObj(String str, TypeReference<T> clz) {
|
||||
try {
|
||||
return jsonMapper.readValue(str, clz);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new UnsupportedOperationException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> List<T> toList(String str, Class<T> clz) {
|
||||
try {
|
||||
return jsonMapper.readValue(str, new TypeReference<List<T>>() {
|
||||
});
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new UnsupportedOperationException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static JsonNode toJsonNode(String str) {
|
||||
try {
|
||||
return jsonMapper.readTree(str);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new UnsupportedOperationException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T nodeToValue(JsonNode node, Class<T> clz) {
|
||||
try {
|
||||
return jsonMapper.treeToValue(node, clz);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new UnsupportedOperationException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static String toStr(Object t) {
|
||||
try {
|
||||
return jsonMapper.writeValueAsString(t);
|
||||
} catch (Exception e) {
|
||||
throw new UnsupportedOperationException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user