mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-11 21:57:56 +08:00
1.2.0
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
package com.gitee.sop.sdk.client;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.gitee.sop.sdk.common.OpenConfig;
|
||||
import com.gitee.sop.sdk.common.RequestForm;
|
||||
import com.gitee.sop.sdk.common.UploadFile;
|
||||
import com.gitee.sop.sdk.response.BaseResponse;
|
||||
import com.gitee.sop.sdk.util.JsonUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
@@ -49,7 +49,7 @@ public class OpenRequest {
|
||||
result.setSubCode(HTTP_ERROR_CODE);
|
||||
result.setSubMsg(e.getMessage());
|
||||
result.setMsg(e.getMessage());
|
||||
return JsonUtil.toJSONString(result);
|
||||
return JSON.toJSONString(result);
|
||||
}
|
||||
|
||||
static class ErrorResponse extends BaseResponse {
|
||||
|
@@ -28,8 +28,10 @@ public abstract class BaseResponse {
|
||||
private String subCode;
|
||||
@JSONField(name = "sub_msg")
|
||||
private String subMsg;
|
||||
@JSONField(serialize = false)
|
||||
private String body;
|
||||
|
||||
@JSONField(serialize = false)
|
||||
public boolean isSuccess() {
|
||||
return StringUtils.isEmpty(subCode);
|
||||
}
|
||||
|
@@ -1,33 +0,0 @@
|
||||
package com.gitee.sop.sdk.util;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
public class JsonUtil {
|
||||
|
||||
/**
|
||||
* 对象转json
|
||||
* @param obj
|
||||
* @return
|
||||
*/
|
||||
public static String toJSONString(Object obj) {
|
||||
if(obj == null) {
|
||||
return "{}";
|
||||
}
|
||||
return JSON.toJSONString(obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* json转对象
|
||||
* @param json
|
||||
* @param clazz
|
||||
* @return
|
||||
*/
|
||||
public static <T> T parseObject(String json, Class<T> clazz) {
|
||||
return JSON.parseObject(json, clazz);
|
||||
}
|
||||
|
||||
public static JSONObject parseJSONObject(String json) {
|
||||
return JSON.parseObject(json);
|
||||
}
|
||||
}
|
@@ -39,7 +39,8 @@ public class SdkTest extends TestCase {
|
||||
|
||||
if (response.isSuccess()) {
|
||||
// 返回结果
|
||||
System.out.println(response);
|
||||
System.out.println(String.format("成功!response:%s\n响应原始内容:%s",
|
||||
JSON.toJSONString(response), response.getBody()));
|
||||
} else {
|
||||
System.out.println("错误,subCode:" + response.getSubCode() + ", subMsg:" + response.getSubMsg());
|
||||
}
|
||||
|
Reference in New Issue
Block a user