1.搭建分布式事务框架
2.项目引入rocketmq实现集群广播
This commit is contained in:
zhongzb
2023-08-14 22:57:08 +08:00
parent 6dd2a27df7
commit 7c21b4127e
47 changed files with 1200 additions and 281 deletions

View File

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