解决某些java版本下反序列化IMResult<Void>失败问题
This commit is contained in:
@@ -22,7 +22,7 @@ import java.lang.reflect.Type;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
|
||||
public class AdminHttpUtils {
|
||||
public class AdminHttpUtils extends JsonUtils {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(AdminHttpUtils.class);
|
||||
|
||||
private static String adminUrl;
|
||||
@@ -152,17 +152,4 @@ public class AdminHttpUtils {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static <T> IMResult<T> fromJsonObject(String content, Class<T> clazz) {
|
||||
Type type = TypeBuilder
|
||||
.newInstance(IMResult.class)
|
||||
.addTypeParam(clazz)
|
||||
.build();
|
||||
return new Gson().fromJson(content, type);
|
||||
}
|
||||
|
||||
private static boolean isNullOrEmpty(String str) {
|
||||
return str == null || str.isEmpty();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.lang.reflect.Type;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
|
||||
public class ChannelHttpUtils {
|
||||
public class ChannelHttpUtils extends JsonUtils {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ChannelHttpUtils.class);
|
||||
|
||||
private String imurl;
|
||||
@@ -103,18 +103,6 @@ public class ChannelHttpUtils {
|
||||
}
|
||||
}
|
||||
|
||||
private static <T> IMResult<T> fromJsonObject(String content, Class<T> clazz) {
|
||||
Type type = TypeBuilder
|
||||
.newInstance(IMResult.class)
|
||||
.addTypeParam(clazz)
|
||||
.build();
|
||||
return new Gson().fromJson(content, type);
|
||||
}
|
||||
|
||||
private static boolean isNullOrEmpty(String str) {
|
||||
return str == null || str.isEmpty();
|
||||
}
|
||||
|
||||
public String getChannelId() {
|
||||
return channelId;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package cn.wildfirechat.sdk.utilities;
|
||||
|
||||
import cn.wildfirechat.sdk.model.IMResult;
|
||||
import com.google.gson.Gson;
|
||||
import ikidou.reflect.TypeBuilder;
|
||||
|
||||
public class JsonUtils {
|
||||
|
||||
public static <T> IMResult<T> fromJsonObject(String content, Class<T> clazz) {
|
||||
TypeBuilder builder = TypeBuilder.newInstance(IMResult.class);
|
||||
if (!clazz.equals(Void.class)) {
|
||||
builder.addTypeParam(clazz);
|
||||
}
|
||||
return new Gson().fromJson(content, builder.build());
|
||||
}
|
||||
|
||||
public static boolean isNullOrEmpty(String str) {
|
||||
return str == null || str.isEmpty();
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@ import java.lang.reflect.Type;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
|
||||
public class RobotHttpUtils {
|
||||
public class RobotHttpUtils extends JsonUtils {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(RobotHttpUtils.class);
|
||||
|
||||
private final String url;
|
||||
@@ -106,18 +106,6 @@ public class RobotHttpUtils {
|
||||
}
|
||||
}
|
||||
|
||||
private static <T> IMResult<T> fromJsonObject(String content, Class<T> clazz) {
|
||||
Type type = TypeBuilder
|
||||
.newInstance(IMResult.class)
|
||||
.addTypeParam(clazz)
|
||||
.build();
|
||||
return new Gson().fromJson(content, type);
|
||||
}
|
||||
|
||||
private static boolean isNullOrEmpty(String str) {
|
||||
return str == null || str.isEmpty();
|
||||
}
|
||||
|
||||
public String getRobotId() {
|
||||
return robotId;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user