diff --git a/static_core/plugins/ets/sdk/api/@ohos.buffer.ets b/static_core/plugins/ets/sdk/api/@ohos.buffer.ets index 5f6a04ca65a3dcc3d9fdca6c832558a4def5d15c..681b6bb417e25c86de62822ad8d351c1c3574f53 100644 --- a/static_core/plugins/ets/sdk/api/@ohos.buffer.ets +++ b/static_core/plugins/ets/sdk/api/@ohos.buffer.ets @@ -669,7 +669,7 @@ export default namespace buffer { * A class representing a fixed-length sequence of bytes. * Provides methods for reading and manipulating binary data with various encodings. */ - export class Buffer implements jsonx.JsonElementDeserializable { + export class Buffer implements jsonx.JsonElementSerializable { /** The underlying ArrayBuffer storing the binary data */ private bufferData: ArrayBuffer; /** The offset into the buffer where this Buffer instance starts */ diff --git a/static_core/plugins/ets/stdlib/escompat/json.ets b/static_core/plugins/ets/stdlib/escompat/json.ets index b1b37e04791a292cb3608699940ea606ea6e2664..84639584e706dd3eee52ae655de725e92096eed7 100644 --- a/static_core/plugins/ets/stdlib/escompat/json.ets +++ b/static_core/plugins/ets/stdlib/escompat/json.ets @@ -568,22 +568,22 @@ export class JSON { } /** - * Converts a JsonElementDeserializable to a JSON string. + * Converts a JsonElementSerializable to a JSON string. * @param elem - The JsonElementDeserializable to stringify * @returns The JSON string representation */ - public static stringifyJsonElement(elem: jsonx.JsonElementDeserializable): string { + public static stringifyJsonElement(elem: jsonx.JsonElementSerializable): string { return JSON.stringifyJsonElement(elem.toJSON()) } /** - * Converts a JsonElementDeserializable to a JSON string with optional formatting. + * Converts a JsonElementSerializable to a JSON string with optional formatting. * @param elem - The JsonElementDeserializable to stringify * @param replacer - Array of keys to include (currently not implemented) * @param space - String or number of spaces for indentation * @returns The JSON string representation */ - public static stringifyJsonElement(elem: jsonx.JsonElementDeserializable, replacer?: (double | string)[], space?: int | string): string { + public static stringifyJsonElement(elem: jsonx.JsonElementSerializable, replacer?: (double | string)[], space?: int | string): string { return JSON.stringifyJsonElement(elem.toJSON(), replacer, space) } @@ -781,7 +781,7 @@ class JSONWriter { this.writeESCompatRecord(temp) } else if (obj instanceof ESValue) { this.writeInteropESValue(obj) - } else if (obj instanceof jsonx.JsonElementDeserializable) { + } else if (obj instanceof jsonx.JsonElementSerializable) { this.buffer.append(JSON.stringifyJsonElement(obj)) } else if (obj instanceof ArrayBuffer) { this.buffer.append(JSONObject.EMPTY) diff --git a/static_core/plugins/ets/stdlib/std/core/Json.ets b/static_core/plugins/ets/stdlib/std/core/Json.ets index 3f73768e2eca718a877e30e62c070744180821e5..0b8a5a6115e7acfa0bba8656e295c50df57d9a19 100644 --- a/static_core/plugins/ets/stdlib/std/core/Json.ets +++ b/static_core/plugins/ets/stdlib/std/core/Json.ets @@ -778,10 +778,10 @@ export namespace jsonx { */ export interface JsonElementSerializable { /** - * Deserializes an object from a JsonElement. - * @param {JsonElement} jsonElem - The JSON element to deserialize from + * Serializes an object to a JsonElement. + * @returns {JsonElement} The JSON representation of the object */ - fromJSON(jsonElem: JsonElement) + toJSON(): JsonElement } /** @@ -790,10 +790,10 @@ export namespace jsonx { */ export interface JsonElementDeserializable { /** - * Serializes an object to a JsonElement. - * @returns {JsonElement} The JSON representation of the object + * Deserializes an object from a JsonElement. + * @param {JsonElement} jsonElem - The JSON element to deserialize from */ - toJSON(): JsonElement + fromJSON(jsonElem: JsonElement) } } diff --git a/static_core/plugins/ets/tests/ets_func_tests/std/core/json/JsonElementFromJsonTest.ets b/static_core/plugins/ets/tests/ets_func_tests/std/core/json/JsonElementFromJsonTest.ets index deac9377e854fea259ddef7364bd8023a92825dc..047ce9437ae18e6f8b6e0bbee905e970e3079a5e 100644 --- a/static_core/plugins/ets/tests/ets_func_tests/std/core/json/JsonElementFromJsonTest.ets +++ b/static_core/plugins/ets/tests/ets_func_tests/std/core/json/JsonElementFromJsonTest.ets @@ -39,7 +39,7 @@ function testFromJson() { arktest.assertFalse(t1.t2.biz) } -class T2 implements jsonx.JsonElementSerializable { +class T2 implements jsonx.JsonElementDeserializable { biz: boolean fromJSON(jsonElem: jsonx.JsonElement) { @@ -47,7 +47,7 @@ class T2 implements jsonx.JsonElementSerializable { } } -class T1 implements jsonx.JsonElementSerializable { +class T1 implements jsonx.JsonElementDeserializable { foo: int bar: string t2: T2 diff --git a/static_core/plugins/ets/tests/ets_func_tests/std/core/json/JsonElementToJsonTest.ets b/static_core/plugins/ets/tests/ets_func_tests/std/core/json/JsonElementToJsonTest.ets index 3bcdb9955083fc37b978f912ff6333ed01efafe9..7e80b7871a87d69e416da35133c07850b4062002 100644 --- a/static_core/plugins/ets/tests/ets_func_tests/std/core/json/JsonElementToJsonTest.ets +++ b/static_core/plugins/ets/tests/ets_func_tests/std/core/json/JsonElementToJsonTest.ets @@ -30,7 +30,7 @@ function testToJson() { arktest.assertTrue(jsonedT2.getBoolean("biz")) } -class T2 implements jsonx.JsonElementDeserializable { +class T2 implements jsonx.JsonElementSerializable { biz: boolean = true toJSON(): jsonx.JsonElement { @@ -42,7 +42,7 @@ class T2 implements jsonx.JsonElementDeserializable { } } -class T1 implements jsonx.JsonElementDeserializable { +class T1 implements jsonx.JsonElementSerializable { foo: int = 5 bar: string = "34" t2: T2 = new T2