diff --git a/doc/docs/files/10095_SDK开发.md b/doc/docs/files/10095_SDK开发.md index b21bbb04..813e8fec 100644 --- a/doc/docs/files/10095_SDK开发.md +++ b/doc/docs/files/10095_SDK开发.md @@ -6,10 +6,10 @@ ## sdk-java -开放平台对应的sdk,适用于Android。SDK依赖了三个jar包 +SDK依赖了三个jar包 - okhttp.jar 用于网络请求 -- fastjson-android.jar 用于json处理 +- fastjson.jar 用于json处理 - commons-logging.jar 日志处理 ### 接口封装步骤 @@ -104,9 +104,10 @@ public void testGet() { 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(response); + System.out.println("错误,subCode:" + response.getSubCode() + ", subMsg:" + response.getSubMsg()); } } ``` diff --git a/sop-sdk/sdk-java/pom.xml b/sop-sdk/sdk-java/pom.xml index 4cb072ab..95dd5ae2 100644 --- a/sop-sdk/sdk-java/pom.xml +++ b/sop-sdk/sdk-java/pom.xml @@ -24,7 +24,7 @@ com.alibaba fastjson - 1.1.68.android + 1.2.56 diff --git a/sop-sdk/sdk-java/readme.md b/sop-sdk/sdk-java/readme.md index f6c20ed4..cd9890f9 100644 --- a/sop-sdk/sdk-java/readme.md +++ b/sop-sdk/sdk-java/readme.md @@ -3,11 +3,11 @@ sdk for java -开放平台对应的sdk,适用于Android。SDK只依赖了三个jar包 +SDK只依赖了三个jar包 -- okhttp.jar -- fastjson-android.jar -- commons-logging.jar +- okhttp.jar 用于网络请求 +- fastjson.jar 用于json处理 +- commons-logging.jar 日志处理 ## 接口封装步骤 diff --git a/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/client/OpenRequest.java b/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/client/OpenRequest.java index 27e62cc6..2ca5f123 100644 --- a/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/client/OpenRequest.java +++ b/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/client/OpenRequest.java @@ -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 { diff --git a/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/response/BaseResponse.java b/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/response/BaseResponse.java index 4fbf5af7..2a62c393 100644 --- a/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/response/BaseResponse.java +++ b/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/response/BaseResponse.java @@ -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); } diff --git a/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/util/JsonUtil.java b/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/util/JsonUtil.java deleted file mode 100644 index 26551bc8..00000000 --- a/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/util/JsonUtil.java +++ /dev/null @@ -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 parseObject(String json, Class clazz) { - return JSON.parseObject(json, clazz); - } - - public static JSONObject parseJSONObject(String json) { - return JSON.parseObject(json); - } -} diff --git a/sop-sdk/sdk-java/src/test/java/com/gitee/sop/sdk/SdkTest.java b/sop-sdk/sdk-java/src/test/java/com/gitee/sop/sdk/SdkTest.java index 09ecc29e..604b9172 100644 --- a/sop-sdk/sdk-java/src/test/java/com/gitee/sop/sdk/SdkTest.java +++ b/sop-sdk/sdk-java/src/test/java/com/gitee/sop/sdk/SdkTest.java @@ -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()); }