From e88079122a589e8100b39b09b0f5bcad3053649e Mon Sep 17 00:00:00 2001 From: dujiepeng <347302029@qq.com> Date: Tue, 21 Dec 2021 11:22:28 +0800 Subject: [PATCH] fix attributes wrong types. --- .../com/easemob/im_flutter_sdk/EMHelper.java | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/com/easemob/im_flutter_sdk/EMHelper.java b/android/src/main/java/com/easemob/im_flutter_sdk/EMHelper.java index 7af0212a..fca0c3a5 100644 --- a/android/src/main/java/com/easemob/im_flutter_sdk/EMHelper.java +++ b/android/src/main/java/com/easemob/im_flutter_sdk/EMHelper.java @@ -526,7 +526,44 @@ static Map toJson(EMMessage message) { } if (message.ext().size() > 0 && null != message.ext()) { - data.put("attributes", message.ext()); + HashMap map = new HashMap<>(); + for (Map.Entry entry:message.ext().entrySet()) { + String key = entry.getKey().toString(); + try { + JSONObject value = message.getJSONObjectAttribute(key); + map.put(key, value); + continue; + } + catch (HyphenateException e) { + } + try { + boolean value = message.getBooleanAttribute(key); + map.put(key, value); + continue; + } catch (HyphenateException e) { + } + + try { + JSONArray value = message.getJSONArrayAttribute(key); + map.put(key, value); + continue; + } catch (HyphenateException e) { + } + try { + int value = message.getIntAttribute(key); + map.put(key, value); + continue; + } catch (HyphenateException e){ + } + + try { + String value = message.getStringAttribute(key); + map.put(key, value); + continue; + } catch (HyphenateException e) { + } + } + data.put("attributes", map); } data.put("from", message.getFrom()); data.put("to", message.getTo());