From bc7b7b96d5d8996e1d27b2b684d19f077e326913 Mon Sep 17 00:00:00 2001 From: devjeonghwan Date: Mon, 21 Aug 2023 06:06:04 +0900 Subject: [PATCH] Fix json empty object or array bug --- ...e__com_esotericsoftware_kryo_5_0_0_RC1.xml | 2 +- ...dle__com_esotericsoftware_minlog_1_3_0.xml | 2 +- ...com_esotericsoftware_reflectasm_1_11_7.xml | 2 +- ...ackson_core_jackson_annotations_2_13_2.xml | 2 +- ...erxml_jackson_core_jackson_core_2_13_2.xml | 2 +- ...jackson_core_jackson_databind_2_13_2_2.xml | 2 +- ...radle__com_google_code_gson_gson_2_8_9.xml | 2 +- ..._org_apiguardian_apiguardian_api_1_1_2.xml | 2 +- ...adle__org_jetbrains_annotations_22_0_0.xml | 2 +- ..._junit_jupiter_junit_jupiter_api_5_8_2.xml | 2 +- ...nit_jupiter_junit_jupiter_engine_5_8_2.xml | 2 +- ..._platform_junit_platform_commons_1_8_2.xml | 2 +- ...t_platform_junit_platform_engine_1_8_2.xml | 2 +- .../Gradle__org_objenesis_objenesis_2_6.xml | 2 +- ...radle__org_opentest4j_opentest4j_1_2_0.xml | 2 +- .idea/runConfigurations.xml | 10 ------- .../opack/codec/json/JsonCodec.java | 1 + .../opack/test/codec/JsonTest.java | 30 +++++++++++++++++++ 18 files changed, 46 insertions(+), 25 deletions(-) delete mode 100644 .idea/runConfigurations.xml diff --git a/.idea/libraries/Gradle__com_esotericsoftware_kryo_5_0_0_RC1.xml b/.idea/libraries/Gradle__com_esotericsoftware_kryo_5_0_0_RC1.xml index 4a12bda..1eff7af 100644 --- a/.idea/libraries/Gradle__com_esotericsoftware_kryo_5_0_0_RC1.xml +++ b/.idea/libraries/Gradle__com_esotericsoftware_kryo_5_0_0_RC1.xml @@ -1,5 +1,5 @@ - + diff --git a/.idea/libraries/Gradle__com_esotericsoftware_minlog_1_3_0.xml b/.idea/libraries/Gradle__com_esotericsoftware_minlog_1_3_0.xml index edce2f2..b1b116b 100644 --- a/.idea/libraries/Gradle__com_esotericsoftware_minlog_1_3_0.xml +++ b/.idea/libraries/Gradle__com_esotericsoftware_minlog_1_3_0.xml @@ -1,5 +1,5 @@ - + diff --git a/.idea/libraries/Gradle__com_esotericsoftware_reflectasm_1_11_7.xml b/.idea/libraries/Gradle__com_esotericsoftware_reflectasm_1_11_7.xml index 238fd37..3364313 100644 --- a/.idea/libraries/Gradle__com_esotericsoftware_reflectasm_1_11_7.xml +++ b/.idea/libraries/Gradle__com_esotericsoftware_reflectasm_1_11_7.xml @@ -1,5 +1,5 @@ - + diff --git a/.idea/libraries/Gradle__com_fasterxml_jackson_core_jackson_annotations_2_13_2.xml b/.idea/libraries/Gradle__com_fasterxml_jackson_core_jackson_annotations_2_13_2.xml index 71c29c2..2553398 100644 --- a/.idea/libraries/Gradle__com_fasterxml_jackson_core_jackson_annotations_2_13_2.xml +++ b/.idea/libraries/Gradle__com_fasterxml_jackson_core_jackson_annotations_2_13_2.xml @@ -1,5 +1,5 @@ - + diff --git a/.idea/libraries/Gradle__com_fasterxml_jackson_core_jackson_core_2_13_2.xml b/.idea/libraries/Gradle__com_fasterxml_jackson_core_jackson_core_2_13_2.xml index 4da485f..8b1adfd 100644 --- a/.idea/libraries/Gradle__com_fasterxml_jackson_core_jackson_core_2_13_2.xml +++ b/.idea/libraries/Gradle__com_fasterxml_jackson_core_jackson_core_2_13_2.xml @@ -1,5 +1,5 @@ - + diff --git a/.idea/libraries/Gradle__com_fasterxml_jackson_core_jackson_databind_2_13_2_2.xml b/.idea/libraries/Gradle__com_fasterxml_jackson_core_jackson_databind_2_13_2_2.xml index 6f05718..af3e336 100644 --- a/.idea/libraries/Gradle__com_fasterxml_jackson_core_jackson_databind_2_13_2_2.xml +++ b/.idea/libraries/Gradle__com_fasterxml_jackson_core_jackson_databind_2_13_2_2.xml @@ -1,5 +1,5 @@ - + diff --git a/.idea/libraries/Gradle__com_google_code_gson_gson_2_8_9.xml b/.idea/libraries/Gradle__com_google_code_gson_gson_2_8_9.xml index 50096b2..ee99a23 100644 --- a/.idea/libraries/Gradle__com_google_code_gson_gson_2_8_9.xml +++ b/.idea/libraries/Gradle__com_google_code_gson_gson_2_8_9.xml @@ -1,5 +1,5 @@ - + diff --git a/.idea/libraries/Gradle__org_apiguardian_apiguardian_api_1_1_2.xml b/.idea/libraries/Gradle__org_apiguardian_apiguardian_api_1_1_2.xml index ec7423e..c32e243 100644 --- a/.idea/libraries/Gradle__org_apiguardian_apiguardian_api_1_1_2.xml +++ b/.idea/libraries/Gradle__org_apiguardian_apiguardian_api_1_1_2.xml @@ -1,5 +1,5 @@ - + diff --git a/.idea/libraries/Gradle__org_jetbrains_annotations_22_0_0.xml b/.idea/libraries/Gradle__org_jetbrains_annotations_22_0_0.xml index a9c34e9..9b98629 100644 --- a/.idea/libraries/Gradle__org_jetbrains_annotations_22_0_0.xml +++ b/.idea/libraries/Gradle__org_jetbrains_annotations_22_0_0.xml @@ -1,5 +1,5 @@ - + diff --git a/.idea/libraries/Gradle__org_junit_jupiter_junit_jupiter_api_5_8_2.xml b/.idea/libraries/Gradle__org_junit_jupiter_junit_jupiter_api_5_8_2.xml index 34a7f43..60ca08f 100644 --- a/.idea/libraries/Gradle__org_junit_jupiter_junit_jupiter_api_5_8_2.xml +++ b/.idea/libraries/Gradle__org_junit_jupiter_junit_jupiter_api_5_8_2.xml @@ -1,5 +1,5 @@ - + diff --git a/.idea/libraries/Gradle__org_junit_jupiter_junit_jupiter_engine_5_8_2.xml b/.idea/libraries/Gradle__org_junit_jupiter_junit_jupiter_engine_5_8_2.xml index 7e6bb5f..b9bc9a3 100644 --- a/.idea/libraries/Gradle__org_junit_jupiter_junit_jupiter_engine_5_8_2.xml +++ b/.idea/libraries/Gradle__org_junit_jupiter_junit_jupiter_engine_5_8_2.xml @@ -1,5 +1,5 @@ - + diff --git a/.idea/libraries/Gradle__org_junit_platform_junit_platform_commons_1_8_2.xml b/.idea/libraries/Gradle__org_junit_platform_junit_platform_commons_1_8_2.xml index a591818..ca1c45c 100644 --- a/.idea/libraries/Gradle__org_junit_platform_junit_platform_commons_1_8_2.xml +++ b/.idea/libraries/Gradle__org_junit_platform_junit_platform_commons_1_8_2.xml @@ -1,5 +1,5 @@ - + diff --git a/.idea/libraries/Gradle__org_junit_platform_junit_platform_engine_1_8_2.xml b/.idea/libraries/Gradle__org_junit_platform_junit_platform_engine_1_8_2.xml index 0512ca7..d1d20da 100644 --- a/.idea/libraries/Gradle__org_junit_platform_junit_platform_engine_1_8_2.xml +++ b/.idea/libraries/Gradle__org_junit_platform_junit_platform_engine_1_8_2.xml @@ -1,5 +1,5 @@ - + diff --git a/.idea/libraries/Gradle__org_objenesis_objenesis_2_6.xml b/.idea/libraries/Gradle__org_objenesis_objenesis_2_6.xml index a37a39c..33ae966 100644 --- a/.idea/libraries/Gradle__org_objenesis_objenesis_2_6.xml +++ b/.idea/libraries/Gradle__org_objenesis_objenesis_2_6.xml @@ -1,5 +1,5 @@ - + diff --git a/.idea/libraries/Gradle__org_opentest4j_opentest4j_1_2_0.xml b/.idea/libraries/Gradle__org_opentest4j_opentest4j_1_2_0.xml index c0ad60c..b904752 100644 --- a/.idea/libraries/Gradle__org_opentest4j_opentest4j_1_2_0.xml +++ b/.idea/libraries/Gradle__org_opentest4j_opentest4j_1_2_0.xml @@ -1,5 +1,5 @@ - + diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml deleted file mode 100644 index 797acea..0000000 --- a/.idea/runConfigurations.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/src/main/java/com/realtimetech/opack/codec/json/JsonCodec.java b/src/main/java/com/realtimetech/opack/codec/json/JsonCodec.java index e31a968..7faa2ad 100644 --- a/src/main/java/com/realtimetech/opack/codec/json/JsonCodec.java +++ b/src/main/java/com/realtimetech/opack/codec/json/JsonCodec.java @@ -789,6 +789,7 @@ protected void doEncode(@NotNull Writer writer, @NotNull OpackValue opackValue) currentContextIndex = this.decodeBaseStack.peek(); currentContext = (OpackValue) this.decodeValueStack.get(currentContextIndex); currentContextType = currentContext.getClass(); + literalMode = false; } break; diff --git a/src/test/java/com/realtimetech/opack/test/codec/JsonTest.java b/src/test/java/com/realtimetech/opack/test/codec/JsonTest.java index 912c267..e544d04 100644 --- a/src/test/java/com/realtimetech/opack/test/codec/JsonTest.java +++ b/src/test/java/com/realtimetech/opack/test/codec/JsonTest.java @@ -75,6 +75,36 @@ public void object_to_string_to_object() throws DecodeException, EncodeException Assertions.assertEquals(opackValue1.toString(), opackValue2.toString()); } + @Test + public void empty_object() throws DecodeException, EncodeException { + String targetData = "{\"object\":{},\"value\":2147483648}"; + + JsonCodec jsonCodec = new JsonCodec.Builder().create(); + + OpackValue opackValue1 = jsonCodec.decode(targetData); + + String middle = jsonCodec.encode(opackValue1); + OpackValue opackValue2 = jsonCodec.decode(middle); + + Assertions.assertEquals(opackValue1, opackValue2); + Assertions.assertEquals(opackValue1.toString(), opackValue2.toString()); + } + + @Test + public void empty_array() throws DecodeException, EncodeException { + String targetData = "{\"array\":[],\"value\":2147483648}"; + + JsonCodec jsonCodec = new JsonCodec.Builder().create(); + + OpackValue opackValue1 = jsonCodec.decode(targetData); + + String middle = jsonCodec.encode(opackValue1); + OpackValue opackValue2 = jsonCodec.decode(middle); + + Assertions.assertEquals(opackValue1, opackValue2); + Assertions.assertEquals(opackValue1.toString(), opackValue2.toString()); + } + @Test public void string_to_object_to_string_object() throws DecodeException, EncodeException { OpackValue opackValue = CommonOpackValue.create();