|
@@ -1,5 +1,6 @@
|
|
|
package org.thyy.socket.service;
|
|
|
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.fastjson2.JSON;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
import org.springframework.web.socket.TextMessage;
|
|
@@ -48,10 +49,15 @@ public interface Business {
|
|
|
default void sendMessage(JSONObject json) {
|
|
|
}
|
|
|
|
|
|
- static JSONObject attemptToConvertJson(String json, Consumer<JSONObject> consumer) {
|
|
|
- JSONObject jsonObject = JSON.parseObject(json);
|
|
|
- consumer.accept(jsonObject);
|
|
|
- return null;
|
|
|
+ static void attemptToConvertJson(String json, Consumer<JSONObject> consumer) {
|
|
|
+ if (!JSONUtil.isTypeJSON(json)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ JSONObject jsonObject = JSON.parseObject(json);
|
|
|
+ consumer.accept(jsonObject);
|
|
|
+ } catch (Exception ignore) {
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|