From 99bc815e07e39354f51421b77f4012ffd35594d8 Mon Sep 17 00:00:00 2001
From: wjc <1243177876@qq.com>
Date: 星期三, 28 六月 2023 18:03:00 +0800
Subject: [PATCH] 2023年06月28日18:02:58
---
HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/LinkResponseUtils.java | 73 ++++++++++++++++++++++++++++++++++++
1 files changed, 73 insertions(+), 0 deletions(-)
diff --git a/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/LinkResponseUtils.java b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/LinkResponseUtils.java
new file mode 100644
index 0000000..57ca709
--- /dev/null
+++ b/HDLLinkLocalSdk/src/main/java/com/hdl/sdk/link/core/utils/LinkResponseUtils.java
@@ -0,0 +1,73 @@
+package com.hdl.sdk.link.core.utils;
+
+import android.text.TextUtils;
+
+import com.google.gson.reflect.TypeToken;
+import com.hdl.sdk.link.common.utils.LogUtils;
+import com.hdl.sdk.link.common.utils.gson.GsonConvert;
+
+import com.hdl.sdk.link.core.bean.LinkResponse;
+import com.hdl.sdk.link.core.bean.response.BaseLocalResponse;
+import com.hdl.sdk.link.core.bean.response.BaseLocalWithCodeResponse;
+
+import java.lang.reflect.Type;
+
+/**
+ * Created by jlchen on 1/6/22.
+ */
+public class LinkResponseUtils<T> {
+
+ public Type getType(){
+ return new TypeToken<BaseLocalResponse<T>>() {}.getType();
+ }
+
+ /**
+ * 杞崲鎻愬彇LinkResponse閲岄潰鐨刼bjects
+ *
+ * @param msg
+ * @return
+ */
+ public static <T> T convertLinkResponse(Object msg, Type type) {
+ T bean = null;
+ if (msg != null && msg instanceof LinkResponse) {
+ LinkResponse linkResponse = (LinkResponse) msg;
+ String data = linkResponse.getData();
+ if (!TextUtils.isEmpty(data)) {
+ try {
+ final BaseLocalResponse<T> response = GsonConvert.getGson().fromJson(data, type);
+ if (response != null) {
+ bean = response.getObjects();
+ }
+ } catch (Exception e) {
+ LogUtils.e("convertLinkResponse catch:" + e.getMessage());
+ }
+ }
+ }
+ return bean;
+ }
+
+ /**
+ * 杞崲鎻愬彇LinkResponse閲岄潰鐨刼bjects 鍙湁杩斿洖code 鍒ゆ柇200鏄垚鍔�
+ *
+ * @param msg
+ * @return
+ */
+ public static <T> T convertLinkWithCodeResponse(Object msg, Type type) {
+ T bean = null;
+ if (msg != null && msg instanceof LinkResponse) {
+ LinkResponse linkResponse = (LinkResponse) msg;
+ String data = linkResponse.getData();
+ if (!TextUtils.isEmpty(data)) {
+ try {
+ final BaseLocalWithCodeResponse<T> response = GsonConvert.getGson().fromJson(data, type);
+ if (response != null) {
+ bean = response.getCode();
+ }
+ } catch (Exception e) {
+ LogUtils.e("convertLinkResponse catch:" + e.getMessage());
+ }
+ }
+ }
+ return bean;
+ }
+}
--
Gitblit v1.8.0