You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fory.apache.org by ch...@apache.org on 2026/09/12 16:07:30 UTC

(fory) branch main updated: fix(android): align Kotlin JSON inclusion assertions (#4041)

This is an automated email from the ASF dual-hosted git repository.

chaokunyang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/fory.git


The following commit(s) were added to refs/heads/main by this push:
     new bfca39fa7 fix(android): align Kotlin JSON inclusion assertions (#4041)
bfca39fa7 is described below

commit bfca39fa75ade8412057207f85cf0d6e34725028
Author: Shawn Yang <sh...@gmail.com>
AuthorDate: Sun Sep 13 00:07:25 2026 +0800

    fix(android): align Kotlin JSON inclusion assertions (#4041)
    
    After #4040, the Android metadata scenario still expected `label = null`
    to survive a round trip with default inclusion. The writer now correctly
    omits that property, and the reader restores its `"android-default"`
    constructor default, causing both Android API 26 and API 36 CI to fail.
    
    Update the scenario to assert omission and default restoration, then
    explicitly enable `writeNullFields(true)` and verify the null-preserving
    round trip. Cover both String and UTF-8 output/input while retaining the
    existing metadata, default-mask, singleton, and shared-corpus checks.
    
    Validation is delegated to CI as requested; the local test run was
    stopped before completion.
    
    Fixes the [Android CI
    failure](https://github.com/apache/fory/actions/runs/34702925778/job/103577771632).
---
 .../apache/fory/android/AndroidKotlinJsonScenarios.kt   | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/integration_tests/android_tests/src/main/kotlin/org/apache/fory/android/AndroidKotlinJsonScenarios.kt b/integration_tests/android_tests/src/main/kotlin/org/apache/fory/android/AndroidKotlinJsonScenarios.kt
index a36596d01..86f02a2de 100644
--- a/integration_tests/android_tests/src/main/kotlin/org/apache/fory/android/AndroidKotlinJsonScenarios.kt
+++ b/integration_tests/android_tests/src/main/kotlin/org/apache/fory/android/AndroidKotlinJsonScenarios.kt
@@ -88,7 +88,22 @@ internal object AndroidKotlinJsonScenarios {
                 .build()
         val accountType = jsonTypeRef<AndroidKotlinAccount>()
         val value = AndroidKotlinAccount(26, "android", null)
-        check(json.fromJson(json.toJson(value, accountType), accountType) == value)
+        // Omitting null restores the constructor default; explicit null inclusion preserves null.
+        // Assert inclusion independently of the reflected property order.
+        val text = json.toJson(value, accountType)
+        check(!text.contains("\"label\":")) { text }
+        check(json.toJsonBytes(value, accountType).decodeToString() == text)
+        val defaulted = AndroidKotlinAccount(26, "android")
+        check(json.fromJson(text, accountType) == defaulted)
+        check(json.fromJson(text.toByteArray(), accountType) == defaulted)
+
+        val jsonWithNulls =
+            ForyJsonKotlin.builder().writeNullFields(true).withAsyncCompilation(false).build()
+        val textWithNulls = jsonWithNulls.toJson(value, accountType)
+        check(textWithNulls.contains("\"label\":null")) { textWithNulls }
+        check(jsonWithNulls.toJsonBytes(value, accountType).decodeToString() == textWithNulls)
+        check(jsonWithNulls.fromJson(textWithNulls, accountType) == value)
+        check(jsonWithNulls.fromJson(textWithNulls.toByteArray(), accountType) == value)
         check(
             json.fromJson("{\"id\":27,\"name\":\"default\"}", accountType) ==
                 AndroidKotlinAccount(27, "default")


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org