Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(android): compatible HashMap and ArrayList for ArgumentUtils #3788

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import com.tencent.mtt.hippy.modules.Promise;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
Expand Down Expand Up @@ -125,8 +127,12 @@ private static void parseObjectGotoArray(HippyArray array, Object obj) throws JS
array.pushBoolean((Boolean) obj);
} else if (cls == HippyArray.class) {
array.pushArray((HippyArray) obj);
} else if (cls == ArrayList.class || cls == List.class) {
array.pushArray(new HippyArray((List) obj));
} else if (cls == HippyMap.class) {
array.pushMap((HippyMap) obj);
} else if (cls == HashMap.class || cls == Map.class) {
array.pushMap(new HippyMap((Map) obj));
} else if (cls == JSONArray.class) {
HippyArray arr = new HippyArray();
JSONArray jsonArr = (JSONArray) obj;
Expand Down Expand Up @@ -228,9 +234,9 @@ private static void objectToJson(StringBuilder builder, Object obj) {
builder.append(obj);
} else if (obj.getClass().isAssignableFrom(float.class) || obj instanceof Float) {
builder.append(Float.isNaN((float) obj) ? 0 : obj);
} else if (obj instanceof HippyArray) {
} else if (obj instanceof HippyArray || obj instanceof ArrayList) {
builder.append("[");
HippyArray array = (HippyArray) obj;
HippyArray array = (obj instanceof HippyArray) ? (HippyArray) obj : new HippyArray((ArrayList) obj);
int length = array.size();
for (int i = 0; i < length; i++) {
objectToJson(builder, array.getObject(i));
Expand All @@ -239,9 +245,9 @@ private static void objectToJson(StringBuilder builder, Object obj) {
}
}
builder.append("]");
} else if (obj instanceof HippyMap) {
} else if (obj instanceof HippyMap || obj instanceof HashMap) {
builder.append("{");
HippyMap map = (HippyMap) obj;
HippyMap map = (obj instanceof HippyMap) ? (HippyMap) obj : new HippyMap((HashMap) obj);;
Set<String> keys = map.keySet();
boolean hasComma = false;
for (String key : keys) {
Expand Down Expand Up @@ -285,11 +291,11 @@ public static Object parseArgument(Type paramCls, HippyArray array, int index) {
return (float) array.getDouble(index);
}

if (paramCls == HippyArray.class) {
if (paramCls == HippyArray.class || paramCls == ArrayList.class || paramCls == List.class) {
return array.getArray(index);
}

if (paramCls == HippyMap.class) {
if (paramCls == HippyMap.class || paramCls == HashMap.class || paramCls == Map.class) {
return array.getMap(index);
}

Expand Down Expand Up @@ -321,11 +327,11 @@ public static Object parseArgument(Type paramCls, HippyMap map, String key) {
return map.getBoolean(key);
}

if (paramCls == HippyArray.class) {
if (paramCls == HippyArray.class || paramCls == ArrayList.class || paramCls == List.class) {
return map.getArray(key);
}

if (paramCls == HippyMap.class) {
if (paramCls == HippyMap.class || paramCls == HashMap.class || paramCls == Map.class) {
return map.getMap(key);
}

Expand Down Expand Up @@ -541,6 +547,8 @@ private static boolean isSupportedObject(Class clazz) {
|| clazz == String.class
|| clazz == HippyArray.class
|| clazz == HippyMap.class
|| clazz == ArrayList.class
|| clazz == HashMap.class
|| clazz == Promise.class
|| clazz.getAnnotation(HippyTurboObj.class) != null) {
return true;
Expand Down
Loading