1package io.flutter.plugin.common;
3import androidx.annotation.Nullable;
4import java.lang.reflect.Array;
5import java.util.ArrayList;
6import java.util.Collection;
7import java.util.HashMap;
8import java.util.Iterator;
11import org.json.JSONArray;
12import org.json.JSONObject;
22 public static Object
unwrap(@Nullable Object o) {
23 if (JSONObject.NULL.equals(o) || o ==
null) {
26 if (o instanceof Boolean
28 || o instanceof Character
29 || o instanceof Double
31 || o instanceof Integer
34 || o instanceof String) {
38 if (o instanceof JSONArray) {
40 JSONArray array = (JSONArray) o;
41 for (
int i = 0;
i < array.length();
i++) {
46 if (o instanceof JSONObject) {
47 Map<String, Object>
map =
new HashMap<>();
48 JSONObject jsonObject = (JSONObject) o;
49 Iterator<String> keyIterator = jsonObject.keys();
50 while (keyIterator.hasNext()) {
51 String
key = keyIterator.next();
56 }
catch (Exception ignored) {
63 public static Object
wrap(@Nullable Object o) {
65 return JSONObject.NULL;
67 if (o instanceof JSONArray || o instanceof JSONObject) {
70 if (o.equals(JSONObject.NULL)) {
74 if (o instanceof Collection) {
75 JSONArray
result =
new JSONArray();
78 }
else if (o.getClass().isArray()) {
79 JSONArray
result =
new JSONArray();
80 int length = Array.getLength(o);
84 if (o instanceof Map) {
85 JSONObject
result =
new JSONObject();
86 for (Map.Entry<?, ?> entry : ((Map<?, ?>) o).entrySet())
87 result.put((String) entry.getKey(),
wrap(entry.getValue()));
90 if (o instanceof Boolean
92 || o instanceof Character
93 || o instanceof Double
95 || o instanceof Integer
98 || o instanceof String) {
101 if (o.getClass().getPackage().getName().startsWith(
"java.")) {
104 }
catch (Exception ignored) {
static Object wrap(@Nullable Object o)
static Object unwrap(@Nullable Object o)
SI auto map(std::index_sequence< I... >, Fn &&fn, const Args &... args) -> skvx::Vec< sizeof...(I), decltype(fn(args[0]...))>