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
Apache Fory™ C# supports cross-language serialization with other Fory runtimes.
C# defaults to Xlang(true), but it is good practice to configure it explicitly in interoperability code.
Fory fory = Fory.Builder() .Xlang(true) .Compatible(true) .Build();
[ForyObject] public sealed class Person { public string Name { get; set; } = string.Empty; public int Age { get; set; } } Fory fory = Fory.Builder() .Xlang(true) .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.
Compatible(true) for rolling upgrades.