| title | Cross-Language Serialization |
|---|---|
| sidebar_position | 8 |
| id | cross_language |
| license | Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. |
Apache Fory™ C# supports cross-language serialization with other Fory runtimes.
C# always writes and reads the xlang frame header. There is no separate Xlang(...) builder
option, so interoperability code only needs to configure the remaining runtime behavior such as
compatibility mode and reference tracking.
Fory fory = Fory.Builder()
.Compatible(true)
.Build();[ForyObject]
public sealed class Person
{
public string Name { get; set; } = string.Empty;
public int Age { get; set; }
}
Fory fory = Fory.Builder()
.Compatible(true)
.Build();
fory.Register<Person>(100);Use the same ID mapping on all languages.
fory.Register<Person>("com.example", "Person");Person person = new() { Name = "Alice", Age = 30 };
byte[] payload = fory.Serialize(person);Fory fory = Fory.builder()
.withLanguage(Language.XLANG)
.withRefTracking(true)
.build();
fory.register(Person.class, 100);
Person value = (Person) fory.deserialize(payloadFromCSharp);import pyfory
fory = pyfory.Fory(xlang=True, ref=True)
fory.register_type(Person, type_id=100)
value = fory.deserialize(payload_from_csharp)See xlang guide for complete mapping.
- Keep type IDs stable and documented.
- Enable
Compatible(true)for rolling upgrades. - Register all user types on both read/write peers.
- Validate integration with real payload round trips.