• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# ArkCompiler Subsystem Changelog
2
3## cl.arkcompiler.1 ArkTSUtils.ASON.stringify Behavior for Handling undefined in Maps and Sets Aligned with EcmaScript Standard Containers
4
5**Access Level**
6
7Public API
8
9**Reason for Change**
10
11If an undefined element is added to a Map or Set and then serialized using **ArkTSUtils.ASON.stringify**, the serialization of the undefined element will be skipped. As a result, the serialized JSON string does not comply with the JSON standard, and an exception is thrown when the JSON string is used.
12
13**Impact of the Change**
14
15This change does not require application adaptation.
16
17Before: After an undefined element is added to a Map or Set, the serialized string is an invalid JSON string. Example:
18
19```ts
20import { ArkTSUtils } from '@kit.ArkTS'
21
22let map = new Map<string | undefined, string | undefined>();
23map.set("a", "A");
24map.set("b", undefined);
25map.set(undefined, "c");
26console.log(ArkTSUtils.ASON.stringify(map));
27// Output before change: {"a":"A","b":,:"c"}
28
29let set = new Set<string | undefined | null>();
30set.add("a");
31set.add(undefined);
32set.add(null);
33console.log(ArkTSUtils.ASON.stringify(set));
34// Output before change: ["a",, null]
35```
36
37After change: undefined is correctly processed. The string serialized by **ArkTSUtils.ASON.stringify** complies with the JSON specifications.
38
39The processing specifications of undefined are aligned with those of the standard containers in Ecmascript. Set is aligned with Array, and Map is aligned with Object.
401. The undefined elements in the array are serialized into the null string.
412. In an object, if the value is undefined, the object is not serialized. If the key is undefined and the value is not undefined, the key is serialized as undefined.
42
43Example:
44
45```ts
46import { ArkTSUtils } from '@kit.ArkTS'
47
48let map = new Map<string | undefined, string | undefined>();
49map.set("a", "A");
50map.set("b", undefined);
51map.set(undefined, "c");
52console.log(ArkTSUtils.ASON.stringify(map));
53// Output after change: {"a":"A","undefined":"c"}.
54
55let set = new Set<string | undefined | null>();
56set.add("a");
57set.add(undefined);
58set.add(null);
59console.log(ArkTSUtils.ASON.stringify(set));
60// Output after change: ["a",null,null].
61```
62
63**Start API Level**
64
6512
66
67**Change Since**
68
69OpenHarmony SDK 5.1.0.50
70
71**Key API/Component Changes**
72
73**ArkTSUTils.ASON.stringify** in the **arkts.utils.d.ets** file
74
75**Adaptation Guide**
76
77After adding undefined elements to a Map or Set, note the change of the return value when **ArkTSUtils.ASON.stringify** is used for serialization.
78