Repository navigation
fix(xlang): canonicalize field name identities across runtimes - #4215
Open
chaokunyang wants to merge 2 commits into
Open
chaokunyang wants to merge 2 commits into
chaokunyang wants to merge 2 commits into
Conversation
chaokunyang
requested review from
ayush00git and
pandalee99
and
a balanced review from Copilot
November 8, 2026 04:31
ayush00git
approved these changes
Nov 8, 2026
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
A C# metadata–fingerprint field-name mismatch and unchecked canonical-name collisions in Python, Go, and JavaScript can cause cross-language reads to fail or silently lose field values.
4 open issues
What changed in this PR
This PR standardizes cross-language field identities to address inconsistent naming and silently dropped compatible fields reported in #4187 and #4202. It preserves declared names for member access and documents migration requirements for affected stored data.
Changes:
- Applies one ASCII snake-case rule to metadata, ordering, fingerprints, and compatible matching across runtimes.
- Adds normalization and cross-language regressions, separates tag identities from name matching, and preserves per-field codec flags.
- Documents compatibility constraints and updates the pinned Rust macOS CI runner.
| File | Description |
|---|---|
| swift/Tests/ForyXlangTests/main.swift | Adds field-name round-trip peer cases. |
| swift/Tests/ForyTests/ForySwiftTests.swift | Tests canonical metadata names. |
| swift/Sources/ForyMacro/ForyObjectMacro.swift | Applies ASCII normalization in macros. |
| swift/Sources/Fory/TypeMeta.swift | Unifies metadata name conversion. |
| scala/fory-scala/src/test/scala-3/org/apache/fory/serializer/scala/ScalaXlangPeer.scala | Adds generated field-name peer coverage. |
| rust/tests/tests/test_cross_language.rs | Adds field-name peer cases. |
| rust/tests/tests/compatible/test_struct.rs | Tests declared/canonical field round trips. |
| rust/fory-derive/src/object/util.rs | Preserves declared identifiers for member access. |
| rust/fory-core/src/util/string_util.rs | Implements and tests canonical normalization. |
| rust/fory-core/src/resolver/meta_resolver.rs | Updates metadata collision fixtures. |
| rust/fory-core/src/meta/type_meta.rs | Canonicalizes encoded and matched names. |
| rust/fory-core/src/meta/meta_string.rs | Restricts compact encoding classification to ASCII. |
| python/pyfory/tests/xlang_test_main.py | Adds field-name peer cases. |
| python/pyfory/tests/test_struct.py | Covers normalization, matching, and skipped-field collisions. |
| python/pyfory/tests/test_cross_language.py | Updates fingerprint nullability inputs. |
| python/pyfory/tests/test_array.py | Updates fingerprint nullability inputs. |
| python/pyfory/struct.py | Shares normalization and stores codec flags by position. |
| python/pyfory/struct.pxi | Preserves per-position flags in Cython codecs. |
| python/pyfory/meta/typedef.py | Matches canonical names separately from tags. |
| python/pyfory/meta/typedef_encoder.py | Encodes canonical field names. |
| python/pyfory/meta/typedef_decoder.py | Clarifies wire-name preservation in comments. |
| python/pyfory/meta/metastring.py | Corrects ASCII encoding eligibility checks. |
| kotlin/fory-kotlin-tests/src/main/kotlin/org/apache/fory/kotlin/xlang/KotlinXlangPeer.kt | Adds generated field-name peer coverage. |
| javascript/test/typemeta.test.ts | Tests normalization and separate tag identities. |
| javascript/test/crossLanguage.test.ts | Adds field-name peer cases. |
| javascript/packages/core/lib/meta/TypeMeta.ts | Unifies normalization and declared-property matching. |
| javascript/packages/core/lib/context.ts | Prevents unmatched names from binding tagged properties. |
| java/fory-latest-jdk-tests/src/test/java/org/apache/fory/integration_tests/ExampleStaticGeneratedSerializerTest.java | Tests generated and runtime compatible matching. |
| java/fory-core/src/test/java/org/apache/fory/xlang/XlangTestBase.java | Adds shared field-name interoperability tests. |
| java/fory-core/src/test/java/org/apache/fory/xlang/SwiftXlangTest.java | Exposes Swift field-name tests. |
| java/fory-core/src/test/java/org/apache/fory/xlang/RustXlangTest.java | Exposes Rust field-name tests. |
| java/fory-core/src/test/java/org/apache/fory/xlang/PythonXlangTest.java | Exposes Python field-name tests. |
| java/fory-core/src/test/java/org/apache/fory/xlang/KotlinXlangTest.java | Enables Kotlin field-name peer cases. |
| java/fory-core/src/test/java/org/apache/fory/xlang/JavaScriptXlangTest.java | Exposes JavaScript field-name tests. |
| java/fory-core/src/test/java/org/apache/fory/xlang/GoXlangTest.java | Exposes Go field-name tests. |
| java/fory-core/src/test/java/org/apache/fory/xlang/DartXlangTest.java | Exposes Dart field-name tests. |
| java/fory-core/src/test/java/org/apache/fory/xlang/CSharpXlangTest.java | Exposes C# field-name tests. |
| java/fory-core/src/test/java/org/apache/fory/xlang/CPPXlangTest.java | Exposes C++ field-name tests. |
| java/fory-core/src/test/java/org/apache/fory/util/StringUtilsTest.java | Adds normalization known-answer cases. |
| java/fory-core/src/test/java/org/apache/fory/serializer/UnknownClassSerializersTest.java | Checks preserved values under canonical wire names. |
| java/fory-core/src/test/java/org/apache/fory/meta/TypeDefTest.java | Compares decoded canonical metadata names. |
| java/fory-core/src/test/java/org/apache/fory/meta/NestedTypeAnnotationTest.java | Adapts nested metadata assertions to canonical names. |
| java/fory-core/src/main/java/org/apache/fory/util/StringUtils.java | Adds canonical conversion; retains row-format behavior. |
| java/fory-core/src/main/java/org/apache/fory/type/Descriptor.java | Uses canonical names for descriptors. |
| java/fory-core/src/main/java/org/apache/fory/serializer/UnknownClass.java | Documents retained wire names. |
| java/fory-core/src/main/java/org/apache/fory/serializer/StaticGeneratedStructSerializer.java | Matches untagged canonical names in generated reads. |
| java/fory-core/src/main/java/org/apache/fory/meta/TypeDefEncoder.java | Writes canonical field names. |
| java/fory-core/src/main/java/org/apache/fory/meta/TypeDefDecoder.java | Preserves received wire names. |
| java/fory-core/src/main/java/org/apache/fory/meta/TypeDef.java | Uses canonical compatible-name lookup. |
| java/fory-core/src/main/java/org/apache/fory/meta/FieldInfo.java | Clarifies name ownership and diagnostic output. |
| go/fory/util.go | Implements canonical ASCII conversion. |
| go/fory/util_test.go | Tests normalization and idempotence. |
| go/fory/type_def.go | Sorts metadata by source indexes. |
| go/fory/tests/xlang/xlang_test_main.go | Adds field-name peer cases. |
| go/fory/tag_test.go | Adapts sorting assertions to index results. |
| go/fory/struct_test.go | Tests tagged collisions and name/tag separation. |
| go/fory/struct_init.go | Preserves field positions and canonical matching. |
| go/fory/field_info.go | Returns source indexes from field sorting. |
| docs/specification/xlang_serialization_spec.md | Defines normalization and compatibility rules. |
| docs/object-serialization/core-concepts.md | Explains identities and migration requirements. |
| dart/packages/fory/test/xlang_protocol_test.dart | Adds normalization known-answer cases. |
| dart/packages/fory/lib/src/serializer/struct_serializer.dart | Normalizes both sides of compatible matching. |
| dart/packages/fory/lib/src/meta/field_info.dart | Adds shared canonical-name conversion. |
| dart/packages/fory/lib/src/codegen/fory_generator.dart | Reuses shared conversion in generated metadata. |
| dart/packages/fory-test/test/cross_lang_test/xlang_test_main.dart | Adds field-name peer dispatch and assertions. |
| dart/packages/fory-test/lib/entity/xlang_test_models.dart | Adds annotated field-name fixtures. |
| csharp/tests/Fory.XlangPeer/Program.cs | Adds naming cases and adjusts reduced-precision fixture names. |
| csharp/tests/Fory.Tests/RuntimeEdgeCaseTests.cs | Tests canonical metadata and bidirectional matching. |
| csharp/src/Fory/TypeMeta.cs | Canonicalizes runtime encoding and matching. |
| csharp/src/Fory.Generator/ForyModelGenerator.Analysis.cs | Applies canonical conversion in source generation. |
| cpp/fory/util/string_util.h | Adds runtime conversion using shared ASCII rules. |
| cpp/fory/util/string_util_test.cc | Checks runtime and compile-time normalization. |
| cpp/fory/serialization/xlang_test_main.cc | Adds field-name peer cases. |
| cpp/fory/serialization/type_resolver.cc | Unifies matching and fingerprint normalization. |
| cpp/fory/serialization/struct_test.cc | Tests canonical names alongside tag identities. |
| compiler/fory_compiler/tests/test_python_generator.py | Corrects the escaped-field identity comment. |
| .github/workflows/ci.yml | Updates the pinned Rust runner to macos-15. |
Review effort: Balanced
| { | ||
| char c = name[i]; | ||
| if (char.IsUpper(c)) | ||
| if (c is >= 'A' and <= 'Z') |
Comment on lines
+69
to
+71
| if (previous >= 'a' && previous <= 'z') || (previous >= '0' && previous <= '9') || | ||
| (previous >= 'A' && previous <= 'Z' && nextLower) { | ||
| buf.WriteByte('_') |
Comment on lines
+916
to
917
| const fieldName = TypeMeta.toSnakeCase(fieldInfo.getFieldName()); | ||
| const metaString = fieldEncoder.encodeByEncodings(fieldName, fieldNameEncoding); |
Comment on lines
+247
to
+249
| field_name = _to_snake_case(field_info.name) | ||
| encoding = FIELD_NAME_ENCODER.compute_encoding(field_name, FIELD_NAME_ENCODINGS) | ||
| meta_string = FIELD_NAME_ENCODER.encode_with_encoding(field_name, encoding) |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Fixes #4187
Fixes #4202
Define one ASCII snake-case rule for field metadata, ordering, fingerprints, and compatible matching across Java (including Kotlin and Scala), Python, Go, Rust, C++, C#, JavaScript, Swift, and Dart. Acronyms, digits, underscores, and non-ASCII characters now have explicit known-answer cases. Generated serializers retain the declared member names for access.
Compatible readers normalize both received and local names, so a peer's
createdAt/CreatedAtandfooURLpopulate localcreated_atandfoo_urlfields. Name matching remains separate from tag IDs and ignored fields. The fix also preserves distinct codec metadata when a skipped field shares a resolved name with a tagged field.Compatibility: names whose canonical identifiers, ordering, or schema hashes change require decoding with the original writer's version/schema and re-encoding. Java and Go native modes share the ordering rule. No alias is provided between historical
foo_u_r_land canonicalfoo_url. Row-format naming remains unchanged.Validation:
CI also replaces the retired
macos-14Rust runner withmacos-15, preserving the pinned arm64 matrix entry. See the GitHub retirement notice.