Skip to content

Commit 18d84a9

Browse files
committed
fix(storage): align getStorageSync with WeChat behavior and add Object type support
Return empty string instead of null/nil when key doesn't exist, matching WeChat official behavior. Applied to iOS and Android. Also add JSONObject/JSONArray support in Android storage set/get and getStorageSync return to preserve structured data types.
1 parent 88b592b commit 18d84a9

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

  • android/dimina/src/main/kotlin/com/didi/dimina/api/storage

android/dimina/src/main/kotlin/com/didi/dimina/api/storage/StorageApi.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ class StorageApi : BaseApiHandler() {
6969
is Double -> SyncResult(JSValue.createNumber(value))
7070
is Float -> SyncResult(JSValue.createNumber(value.toDouble()))
7171
is Boolean -> SyncResult(JSValue.createBoolean(value))
72-
else -> SyncResult(JSValue.createNull())
72+
is JSONArray -> SyncResult(JSValue.createObject(value.toString()))
73+
is JSONObject -> SyncResult(JSValue.createObject(value.toString()))
74+
else -> SyncResult(JSValue.createString(""))
7375
}
7476
}
7577

@@ -192,6 +194,11 @@ class StorageApi : BaseApiHandler() {
192194
storage.encode(typeKey, "Array")
193195
}
194196

197+
is JSONObject -> {
198+
storage.encode(key, data.toString())
199+
storage.encode(typeKey, "Object")
200+
}
201+
195202
is Any -> try {
196203
// For JSON-serializable objects
197204
storage.encode(key, data.toString())
@@ -223,6 +230,11 @@ class StorageApi : BaseApiHandler() {
223230
} catch (_: Exception) {
224231
storage.decodeString(key) // Fallback to String if parsing fails
225232
}
233+
"Object" -> try {
234+
JSONObject(storage.decodeString(key))
235+
} catch (_: Exception) {
236+
storage.decodeString(key) // Fallback to String if parsing fails
237+
}
226238
else -> storage.decodeString(key) // Fallback to String for unknown types
227239
}
228240
}

0 commit comments

Comments
 (0)