blob: f4646fb5faaa7cb382ba5a3ab5c12b6a92ae8746 [file]
<!doctype html><html lang=en-US dir=ltr class="docs-wrapper plugin-docs plugin-id-default docs-version-current docs-doc-page docs-doc-id-object-serialization/native" data-has-hydrated=false><head><meta charset=UTF-8><meta name=generator content="Docusaurus v3.10.1"><title data-rh=true>Native Serialization | Apache Fory™</title><meta data-rh=true name=viewport content="width=device-width, initial-scale=1.0"/><meta data-rh=true property=og:url content=https://fory.apache.org/docs/next/object-serialization/native /><meta data-rh=true property=og:locale content=en_US /><meta data-rh=true property=og:locale:alternate content=zh_CN /><meta data-rh=true name=docusaurus_locale content=en-US /><meta data-rh=true name=docsearch:language content=en-US /><meta data-rh=true http-equiv=Content-Security-Policy content="frame-src 'self' https://ghbtns.com/;"/><meta data-rh=true property=og:image content=https://fory.apache.org/img/logo.png /><meta data-rh=true property=og:image:width content=1500 /><meta data-rh=true property=og:image:height content=1500 /><meta data-rh=true name=twitter:card content=summary_large_image /><meta data-rh=true name=twitter:image content=https://fory.apache.org/img/logo.png /><meta data-rh=true name=docusaurus_version content=current /><meta data-rh=true name=docusaurus_tag content=docs-default-current /><meta data-rh=true name=docsearch:version content=current /><meta data-rh=true name=docsearch:docusaurus_tag content=docs-default-current /><meta data-rh=true property=og:title content="Native Serialization | Apache Fory™"/><meta data-rh=true name=description content="Native serialization uses an implementation-specific wire format and the host language's native"/><meta data-rh=true property=og:description content="Native serialization uses an implementation-specific wire format and the host language's native"/><link data-rh=true rel=icon href=/img/favicon.ico /><link data-rh=true rel=canonical href=https://fory.apache.org/docs/next/object-serialization/native /><link data-rh=true rel=alternate href=https://fory.apache.org/docs/next/object-serialization/native hreflang=en-US /><link data-rh=true rel=alternate href=https://fory.apache.org/zh-CN/docs/next/object-serialization/native hreflang=zh-CN /><link data-rh=true rel=alternate href=https://fory.apache.org/docs/next/object-serialization/native hreflang=x-default /><script data-rh=true type=application/ld+json>{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","item":"https://fory.apache.org/docs/next/object-serialization/native","name":"Native Serialization","position":1}]}</script><link rel=alternate type=application/rss+xml href=/blog/rss.xml title="Apache Fory™ RSS Feed"><link rel=alternate type=application/atom+xml href=/blog/atom.xml title="Apache Fory™ Atom Feed"><script type=text/javascript>"fury.apache.org"===window.location.host&&(window.location.href="https://fory.apache.org"),function(){var i=["0.17","0.16","0.15","0.14","0.13","0.12","0.11","0.10"];if(0!==i.length){var t=window.location.pathname.split("/").filter(Boolean),a=/^[a-z]{2}-[A-Z]{2}$/.test(t[0])?t[0]:null,e=+!!a;if(!("docs"!==t[e]||0>i.indexOf(t[e+1]))){var o=["/archive"];a&&o.push(a),o.push.apply(o,t.slice(e));var n=window.location.pathname.endsWith("/")?"/":"";window.location.replace(o.join("/")+n+window.location.search+window.location.hash)}}}(),function(){var i=window.location.pathname.split("/").filter(Boolean),t="docs"===i[0]?0:/^[a-z]{2}-[A-Z]{2}$/.test(i[0])&&"docs"===i[1]?1:-1;if(!(t<0)){var a=t+1,e=i[a];if(!/^[0-9]+[.][0-9]+(?:[.][0-9]+)?$/.test(e)){"next"===e&&a++;var o={"introduction/overview":"introduction","introduction/benchmark":"benchmarks","start/install":"start","start/usage":"start","guide/xlang":"object-serialization/xlang","guide/xlang/getting_started":"object-serialization/xlang","guide/xlang/serialization":"object-serialization/xlang","guide/java/json_support":"json","guide/rust/external_types":"object-serialization/rust/external-types","guide/dart/external_types":"object-serialization/dart/external-types","guide/swift/external_types":"object-serialization/swift/external-types","guide/csharp/external_types":"object-serialization/csharp/external-types","guide/csharp/basic_serialization":"object-serialization/csharp/basic-serialization","guide/dart/inheritance":"object-serialization/dart/inheritance","benchmarks/rust":"benchmarks/object-serialization/xlang/rust","compiler/compiler_guide":"compiler/getting-started","community/development":"development"}[i.slice(a).join("/")];if(o){var n="/"+i.slice(0,a).join("/");window.location.replace(n+"/"+o+"/"+window.location.search+window.location.hash)}}}}(),function(){var i=window.location.pathname,t=i.split("/").filter(Boolean),a="docs"===t[0]?0:/^[a-z]{2}-[A-Z]{2}$/.test(t[0])&&"docs"===t[1]?1:-1;if(!(a<0)){var e=a+1,o=t[e];if(("next"===o||/^[0-9]+[.][0-9]+(?:[.][0-9]+)?$/.test(o))&&e++,!("docs"!==t[e]||0>["guide","introduction","start"].indexOf(t[e+1]))){t.splice(e,1);var n="/"+t.join("/");i.endsWith("/")&&(n+="/"),window.location.replace(n+window.location.search+window.location.hash)}}}()</script><link rel=stylesheet href=/assets/css/styles.3a1edaa1.css /><script src=/assets/js/runtime~main.cc62af69.js defer></script><script src=/assets/js/main.2bf7de4a.js defer></script></head><body><svg style="display: none;"><defs>
<symbol id=theme-svg-external-link viewBox="0 0 24 24"><path fill=currentColor d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"/></symbol>
</defs></svg>
<script>!function(){var t=function(){try{return new URLSearchParams(window.location.search).get("docusaurus-theme")}catch(t){}}()||function(){try{return window.localStorage.getItem("theme")}catch(t){}}();document.documentElement.setAttribute("data-theme",t||"light"),document.documentElement.setAttribute("data-theme-choice",t||"light")}(),function(){try{for(var[t,e]of new URLSearchParams(window.location.search).entries())if(t.startsWith("docusaurus-data-")){var a=t.replace("docusaurus-data-","data-");document.documentElement.setAttribute(a,e)}}catch(t){}}()</script><div id=__docusaurus><div role=region aria-label="Skip to main content"><a class=skipToContent_fXgn href=#__docusaurus_skipToContent_fallback>Skip to main content</a></div><nav aria-label=Main class="theme-layout-navbar navbar navbar--fixed-top"><div class=navbar__inner><div class="theme-layout-navbar-left navbar__items"><button aria-label="Toggle navigation bar" aria-expanded=false class="navbar__toggle clean-btn" type=button><svg width=30 height=30 viewBox="0 0 30 30" aria-hidden=true><path stroke=currentColor stroke-linecap=round stroke-miterlimit=10 stroke-width=2 d="M4 7h22M4 15h22M4 23h22"/></svg></button><a class=navbar__brand href=/><div class=navbar__logo><img src=/img/fory-logo-light.png alt="Apache Fory™ Logo" class="themedComponent_mlkZ themedComponent--light_NVdE"/><img src=/img/fory-logo-dark.png alt="Apache Fory™ Logo" class="themedComponent_mlkZ themedComponent--dark_xIcU"/></div><b class="navbar__title text--truncate"></b></a><a aria-current=page class="navbar__item navbar__link navbar__link--active" href=/docs/next/introduction/>Docs</a><a class="navbar__item navbar__link" href=/docs/next/specification/xlang_serialization_spec>Specification</a><a class="navbar__item navbar__link" href=/docs/next/community/>Community</a><a class="navbar__item navbar__link" href=/user>Users</a><a class="navbar__item navbar__link" href=/download>Download</a><a class="navbar__item navbar__link" href=/blog>Blog</a></div><div class="theme-layout-navbar-right navbar__items navbar__items--right"><div class="navbar__item dropdown dropdown--hoverable dropdown--right"><a href=# aria-haspopup=true aria-expanded=false role=button class=navbar__link>ASF</a><ul class=dropdown__menu><li><a href=https://www.apache.org/ target=_blank rel="noopener noreferrer" class=dropdown__link>Foundation</a><li><a href=https://www.apache.org/licenses/ target=_blank rel="noopener noreferrer" class=dropdown__link>License</a><li><a href=https://www.apache.org/events/current-event.html target=_blank rel="noopener noreferrer" class=dropdown__link>Events</a><li><a href=https://privacy.apache.org/policies/privacy-policy-public.html target=_blank rel="noopener noreferrer" class=dropdown__link>Privacy</a><li><a href=https://www.apache.org/security/ target=_blank rel="noopener noreferrer" class=dropdown__link>Security</a><li><a href=https://www.apache.org/foundation/sponsorship.html target=_blank rel="noopener noreferrer" class=dropdown__link>Sponsorship</a><li><a href=https://www.apache.org/foundation/thanks.html target=_blank rel="noopener noreferrer" class=dropdown__link>Thanks</a><li><a href=https://www.apache.org/foundation/policies/conduct.html target=_blank rel="noopener noreferrer" class=dropdown__link>Code of Conduct</a></ul></div><div class="navbar__item dropdown dropdown--hoverable dropdown--right"><a class=navbar__link aria-haspopup=true aria-expanded=false role=button href=/docs/next/object-serialization/native>dev</a><ul class=dropdown__menu><li><a aria-current=page class="dropdown__link dropdown__link--active" href=/docs/next/object-serialization/native>dev</a><li><a class=dropdown__link href=/docs/object-serialization/native>1.6.0</a><li><a class=dropdown__link href=/docs/1.5.0/introduction/overview>1.5.0</a><li><a class=dropdown__link href=/docs/1.4.0/introduction/overview>1.4.0</a><li><a class=dropdown__link href=/docs/1.3.0/introduction/overview>1.3.0</a><li><a class=dropdown__link href=/docs/1.2.0/introduction/overview>1.2.0</a><li><a class=dropdown__link href=/docs/1.1.0/introduction/overview>1.1.0</a><li><a class=dropdown__link href=/docs/1.0.0/introduction/overview>1.0.0</a><li><a href=https://fory.apache.org/archive/docs/0.17/introduction/overview/ target=_blank rel="noopener noreferrer" class=dropdown__link>More versions<svg width=12 height=12 aria-label="(opens in new tab)" class=iconExternalLink_nPIU><use href=#theme-svg-external-link /></svg></a></ul></div><a href=https://github.com/apache/fory target=_blank rel="noopener noreferrer" class="navbar__item navbar__link header-github-link" aria-label="GitHub repository"></a><div class="navbar__item dropdown dropdown--hoverable dropdown--right"><a href=# aria-haspopup=true aria-expanded=false role=button class=navbar__link><svg viewBox="0 0 24 24" width=20 height=20 aria-hidden=true class=iconLanguage_nlXk><path fill=currentColor d="M12.87 15.07l-2.54-2.51.03-.03c1.74-1.94 2.98-4.17 3.71-6.53H17V4h-7V2H8v2H1v1.99h11.17C11.5 7.92 10.44 9.75 9 11.35 8.07 10.32 7.3 9.19 6.69 8h-2c.73 1.63 1.73 3.17 2.98 4.56l-5.09 5.02L4 19l5-5 3.11 3.11.76-2.04zM18.5 10h-2L12 22h2l1.12-3h4.75L21 22h2l-4.5-12zm-2.62 7l1.62-4.33L19.12 17h-3.24z"/></svg>English</a><ul class=dropdown__menu><li><a href=/docs/next/object-serialization/native target=_self rel="noopener noreferrer" class="dropdown__link dropdown__link--active" lang=en-US>English</a><li><a href=/zh-CN/docs/next/object-serialization/native target=_self rel="noopener noreferrer" class=dropdown__link lang=zh-CN>简体中文</a></ul></div><div class="toggle_vylO colorModeToggle_DEke"><button class="clean-btn toggleButton_gllP toggleButtonDisabled_aARS" type=button disabled title="system mode" aria-label="Switch between dark and light mode (currently system mode)"><svg viewBox="0 0 24 24" width=24 height=24 aria-hidden=true class="toggleIcon_g3eP lightToggleIcon_pyhR"><path fill=currentColor d="M12,9c1.65,0,3,1.35,3,3s-1.35,3-3,3s-3-1.35-3-3S10.35,9,12,9 M12,7c-2.76,0-5,2.24-5,5s2.24,5,5,5s5-2.24,5-5 S14.76,7,12,7L12,7z M2,13l2,0c0.55,0,1-0.45,1-1s-0.45-1-1-1l-2,0c-0.55,0-1,0.45-1,1S1.45,13,2,13z M20,13l2,0c0.55,0,1-0.45,1-1 s-0.45-1-1-1l-2,0c-0.55,0-1,0.45-1,1S19.45,13,20,13z M11,2v2c0,0.55,0.45,1,1,1s1-0.45,1-1V2c0-0.55-0.45-1-1-1S11,1.45,11,2z M11,20v2c0,0.55,0.45,1,1,1s1-0.45,1-1v-2c0-0.55-0.45-1-1-1C11.45,19,11,19.45,11,20z M5.99,4.58c-0.39-0.39-1.03-0.39-1.41,0 c-0.39,0.39-0.39,1.03,0,1.41l1.06,1.06c0.39,0.39,1.03,0.39,1.41,0s0.39-1.03,0-1.41L5.99,4.58z M18.36,16.95 c-0.39-0.39-1.03-0.39-1.41,0c-0.39,0.39-0.39,1.03,0,1.41l1.06,1.06c0.39,0.39,1.03,0.39,1.41,0c0.39-0.39,0.39-1.03,0-1.41 L18.36,16.95z M19.42,5.99c0.39-0.39,0.39-1.03,0-1.41c-0.39-0.39-1.03-0.39-1.41,0l-1.06,1.06c-0.39,0.39-0.39,1.03,0,1.41 s1.03,0.39,1.41,0L19.42,5.99z M7.05,18.36c0.39-0.39,0.39-1.03,0-1.41c-0.39-0.39-1.03-0.39-1.41,0l-1.06,1.06 c-0.39,0.39-0.39,1.03,0,1.41s1.03,0.39,1.41,0L7.05,18.36z"/></svg><svg viewBox="0 0 24 24" width=24 height=24 aria-hidden=true class="toggleIcon_g3eP darkToggleIcon_wfgR"><path fill=currentColor d="M9.37,5.51C9.19,6.15,9.1,6.82,9.1,7.5c0,4.08,3.32,7.4,7.4,7.4c0.68,0,1.35-0.09,1.99-0.27C17.45,17.19,14.93,19,12,19 c-3.86,0-7-3.14-7-7C5,9.07,6.81,6.55,9.37,5.51z M12,3c-4.97,0-9,4.03-9,9s4.03,9,9,9s9-4.03,9-9c0-0.46-0.04-0.92-0.1-1.36 c-0.98,1.37-2.58,2.26-4.4,2.26c-2.98,0-5.4-2.42-5.4-5.4c0-1.81,0.89-3.42,2.26-4.4C12.92,3.04,12.46,3,12,3L12,3z"/></svg><svg viewBox="0 0 24 24" width=24 height=24 aria-hidden=true class="toggleIcon_g3eP systemToggleIcon_QzmC"><path fill=currentColor d="m12 21c4.971 0 9-4.029 9-9s-4.029-9-9-9-9 4.029-9 9 4.029 9 9 9zm4.95-13.95c1.313 1.313 2.05 3.093 2.05 4.95s-0.738 3.637-2.05 4.95c-1.313 1.313-3.093 2.05-4.95 2.05v-14c1.857 0 3.637 0.737 4.95 2.05z"/></svg></button></div><div class=navbarSearchContainer_Bca1><div class=navbar__search><span aria-label="expand searchbar" role=button class=search-icon tabindex=0></span><input id=search_input_react type=search placeholder=Loading... aria-label=Search class="navbar__search-input search-bar" disabled/></div></div></div></div><div role=presentation class=navbar-sidebar__backdrop></div></nav><div id=__docusaurus_skipToContent_fallback class="theme-layout-main main-wrapper mainWrapper_z2l0"><div class=docsWrapper_hBAB><button aria-label="Scroll back to top" class="clean-btn theme-back-to-top-button backToTopButton_sjWU" type=button></button><div class=docRoot_UBD9><aside class="theme-doc-sidebar-container docSidebarContainer_YfHR"><div class=sidebarViewport_aRkj><div class=sidebar_njMd><nav aria-label="Docs sidebar" class="menu thin-scrollbar menu_SIkG"><ul class="theme-doc-sidebar-menu menu__list"><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class=menu__list-item-collapsible><a class="categoryLink_byQd menu__link menu__link--sublist menu__link--sublist-caret" role=button aria-expanded=false href=/docs/next/introduction/><span title=Introduction class=categoryLinkLabel_W154>Introduction</span></a></div><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class=menu__list-item-collapsible><a class="categoryLink_byQd menu__link menu__link--sublist menu__link--sublist-caret" role=button aria-expanded=false href=/docs/next/start/><span title="Getting Started" class=categoryLinkLabel_W154>Getting Started</span></a></div><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class=menu__list-item-collapsible><a class="categoryLink_byQd menu__link menu__link--sublist menu__link--sublist-caret" role=button aria-expanded=false href=/docs/next/benchmarks/><span title=Benchmarks class=categoryLinkLabel_W154>Benchmarks</span></a></div><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item"><div class=menu__list-item-collapsible><a class="categoryLink_byQd menu__link menu__link--sublist menu__link--sublist-caret menu__link--active" role=button aria-expanded=true href=/docs/next/object-serialization/><span title="Object Serialization" class=categoryLinkLabel_W154>Object Serialization</span></a></div><ul class=menu__list><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-2 menu__list-item"><a class=menu__link tabindex=0 href=/docs/next/object-serialization/><span title=Introduction class=linkLabel_WmDU>Introduction</span></a><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-2 menu__list-item"><a class=menu__link tabindex=0 href=/docs/next/object-serialization/core-concepts><span title="Core Concepts" class=linkLabel_WmDU>Core Concepts</span></a><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-2 menu__list-item"><a class=menu__link tabindex=0 href=/docs/next/object-serialization/xlang><span title="Xlang Serialization" class=linkLabel_WmDU>Xlang Serialization</span></a><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-2 menu__list-item"><a class="menu__link menu__link--active" aria-current=page tabindex=0 href=/docs/next/object-serialization/native><span title="Native Serialization" class=linkLabel_WmDU>Native Serialization</span></a><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-2 menu__list-item menu__list-item--collapsed"><div class=menu__list-item-collapsible><a class="categoryLink_byQd menu__link menu__link--sublist" tabindex=0 href=/docs/next/object-serialization/java/><span title=Java class=categoryLinkLabel_W154>Java</span></a><button aria-label="Expand sidebar category 'Java'" aria-expanded=false type=button class="clean-btn menu__caret"></button></div><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-2 menu__list-item menu__list-item--collapsed"><div class=menu__list-item-collapsible><a class="categoryLink_byQd menu__link menu__link--sublist" tabindex=0 href=/docs/next/object-serialization/python/><span title=Python class=categoryLinkLabel_W154>Python</span></a><button aria-label="Expand sidebar category 'Python'" aria-expanded=false type=button class="clean-btn menu__caret"></button></div><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-2 menu__list-item menu__list-item--collapsed"><div class=menu__list-item-collapsible><a class="categoryLink_byQd menu__link menu__link--sublist" tabindex=0 href=/docs/next/object-serialization/cpp/><span title=C++ class=categoryLinkLabel_W154>C++</span></a><button aria-label="Expand sidebar category 'C++'" aria-expanded=false type=button class="clean-btn menu__caret"></button></div><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-2 menu__list-item menu__list-item--collapsed"><div class=menu__list-item-collapsible><a class="categoryLink_byQd menu__link menu__link--sublist" tabindex=0 href=/docs/next/object-serialization/go/><span title=Go class=categoryLinkLabel_W154>Go</span></a><button aria-label="Expand sidebar category 'Go'" aria-expanded=false type=button class="clean-btn menu__caret"></button></div><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-2 menu__list-item menu__list-item--collapsed"><div class=menu__list-item-collapsible><a class="categoryLink_byQd menu__link menu__link--sublist" tabindex=0 href=/docs/next/object-serialization/rust/><span title=Rust class=categoryLinkLabel_W154>Rust</span></a><button aria-label="Expand sidebar category 'Rust'" aria-expanded=false type=button class="clean-btn menu__caret"></button></div><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-2 menu__list-item menu__list-item--collapsed"><div class=menu__list-item-collapsible><a class="categoryLink_byQd menu__link menu__link--sublist" tabindex=0 href=/docs/next/object-serialization/javascript/><span title=JavaScript/TypeScript class=categoryLinkLabel_W154>JavaScript/TypeScript</span></a><button aria-label="Expand sidebar category 'JavaScript/TypeScript'" aria-expanded=false type=button class="clean-btn menu__caret"></button></div><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-2 menu__list-item menu__list-item--collapsed"><div class=menu__list-item-collapsible><a class="categoryLink_byQd menu__link menu__link--sublist" tabindex=0 href=/docs/next/object-serialization/csharp/><span title=C# class=categoryLinkLabel_W154>C#</span></a><button aria-label="Expand sidebar category 'C#'" aria-expanded=false type=button class="clean-btn menu__caret"></button></div><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-2 menu__list-item menu__list-item--collapsed"><div class=menu__list-item-collapsible><a class="categoryLink_byQd menu__link menu__link--sublist" tabindex=0 href=/docs/next/object-serialization/swift/><span title=Swift class=categoryLinkLabel_W154>Swift</span></a><button aria-label="Expand sidebar category 'Swift'" aria-expanded=false type=button class="clean-btn menu__caret"></button></div><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-2 menu__list-item menu__list-item--collapsed"><div class=menu__list-item-collapsible><a class="categoryLink_byQd menu__link menu__link--sublist" tabindex=0 href=/docs/next/object-serialization/dart/><span title=Dart class=categoryLinkLabel_W154>Dart</span></a><button aria-label="Expand sidebar category 'Dart'" aria-expanded=false type=button class="clean-btn menu__caret"></button></div><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-2 menu__list-item menu__list-item--collapsed"><div class=menu__list-item-collapsible><a class="categoryLink_byQd menu__link menu__link--sublist" tabindex=0 href=/docs/next/object-serialization/scala/><span title=Scala class=categoryLinkLabel_W154>Scala</span></a><button aria-label="Expand sidebar category 'Scala'" aria-expanded=false type=button class="clean-btn menu__caret"></button></div><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-2 menu__list-item menu__list-item--collapsed"><div class=menu__list-item-collapsible><a class="categoryLink_byQd menu__link menu__link--sublist" tabindex=0 href=/docs/next/object-serialization/kotlin/><span title=Kotlin class=categoryLinkLabel_W154>Kotlin</span></a><button aria-label="Expand sidebar category 'Kotlin'" aria-expanded=false type=button class="clean-btn menu__caret"></button></div></ul><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class=menu__list-item-collapsible><a class="categoryLink_byQd menu__link menu__link--sublist menu__link--sublist-caret" role=button aria-expanded=false href=/docs/next/row-format/><span title="Row Format" class=categoryLinkLabel_W154>Row Format</span></a></div><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class=menu__list-item-collapsible><a class="categoryLink_byQd menu__link menu__link--sublist menu__link--sublist-caret" role=button aria-expanded=false href=/docs/next/json/><span title="Fory JSON" class=categoryLinkLabel_W154>Fory JSON</span></a></div><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class=menu__list-item-collapsible><a class="categoryLink_byQd menu__link menu__link--sublist menu__link--sublist-caret" role=button aria-expanded=false href=/docs/next/compiler/><span title="Fory IDL & Compiler" class=categoryLinkLabel_W154>Fory IDL & Compiler</span></a></div><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class=menu__list-item-collapsible><a class="categoryLink_byQd menu__link menu__link--sublist menu__link--sublist-caret" role=button aria-expanded=false href=/docs/next/grpc/><span title="Fory gRPC" class=categoryLinkLabel_W154>Fory gRPC</span></a></div><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class=menu__list-item-collapsible><a class="categoryLink_byQd menu__link menu__link--sublist menu__link--sublist-caret" role=button aria-expanded=false href=/docs/next/development/><span title=Development class=categoryLinkLabel_W154>Development</span></a></div></ul></nav></div></div></aside><main class=docMainContainer_TBSr><div class="container padding-top--md padding-bottom--lg"><div class=row><div class="col docItemCol_VOVn"><div class="theme-doc-version-banner alert alert--warning margin-bottom--md" role=alert><div>This is unreleased documentation for <!-- -->Apache Fory™<!-- --> <b>dev</b> version.</div><div class=margin-top--md>For up-to-date documentation, see the <b><a href=/docs/object-serialization/native>latest version</a></b> (<!-- -->1.6.0<!-- -->).</div></div><div class=docItemContainer_Djhp><article><nav class="theme-doc-breadcrumbs breadcrumbsContainer_Z_bl" aria-label=Breadcrumbs><ul class=breadcrumbs><li class=breadcrumbs__item><a aria-label="Home page" class=breadcrumbs__link href=/><svg viewBox="0 0 24 24" class=breadcrumbHomeIcon_YNFT><path d="M10 19v-5h4v5c0 .55.45 1 1 1h3c.55 0 1-.45 1-1v-7h1.7c.46 0 .68-.57.33-.87L12.67 3.6c-.38-.34-.96-.34-1.34 0l-8.36 7.53c-.34.3-.13.87.33.87H5v7c0 .55.45 1 1 1h3c.55 0 1-.45 1-1z" fill=currentColor /></svg></a><li class=breadcrumbs__item><span class=breadcrumbs__link>Object Serialization</span><li class="breadcrumbs__item breadcrumbs__item--active"><span class=breadcrumbs__link>Native Serialization</span></ul></nav><span class="theme-doc-version-badge badge badge--secondary">Version: dev</span><div class="tocCollapsible_ETCw theme-doc-toc-mobile tocMobile_ITEo"><button type=button class="clean-btn tocCollapsibleButton_TO0P">On this page</button></div><div class="theme-doc-markdown markdown"><header><h1>Native Serialization</h1></header><p>Native serialization uses an implementation-specific wire format and the host language's native
type system. Choose it when every writer and reader uses the same Fory implementation family and
the payload should preserve language-specific types or behavior. Native payloads from different
implementation families are not interchangeable.</p>
<p>Use <a class="" href=/docs/next/object-serialization/xlang>xlang serialization</a> whenever a peer with a different native wire format must read
the bytes. Xlang uses a shared type system and wire format; native mode deliberately stays closer to
the implementation family's native object model.</p>
<p>Native and xlang type support overlap. A type listed on this page is not necessarily exclusive to
native mode; many language-native carriers also work in xlang when they have a portable mapping.
Choose the mode from the data boundary and required wire contract first, then check the language's
type mapping for the specific model.</p>
<h2 class="anchor anchorTargetStickyNavbar_Vzrq" id=when-to-use-native-mode>When To Use Native Mode<a href=#when-to-use-native-mode class=hash-link aria-label="Direct link to When To Use Native Mode" title="Direct link to When To Use Native Mode" translate=no></a></h2>
<p>Native mode is the right choice when:</p>
<ul>
<li class="">every producer and consumer uses one Fory implementation family;</li>
<li class="">the object graph contains language-specific types or behavior outside the portable xlang type
mapping;</li>
<li class="">an application is moving from an existing same-language serializer and should keep its current
object model instead of introducing a cross-language schema; or</li>
<li class="">stored or transported data stays within one implementation family rather than a contract shared
across implementation families.</li>
</ul>
<p>Use xlang instead when peers use different Fory implementation families, when the contract must
remain language-independent, or when portability is more important than the full native object
surface.</p>
<table><thead><tr><th>Scenario<th>Recommended mode<tbody><tr><td>One implementation family with language-specific types<td>Native<tr><td>Replacement for an existing same-language object serializer<td>Native<tr><td>Data exchanged across Fory implementation families<td>Xlang<tr><td>A long-lived contract intended to remain language-independent<td>Xlang</table>
<h2 class="anchor anchorTargetStickyNavbar_Vzrq" id=java>Java<a href=#java class=hash-link aria-label="Direct link to Java" title="Direct link to Java" translate=no></a></h2>
<p>Choose <a class="" href=/docs/next/object-serialization/java/native>Java native serialization</a> for Java/JVM-only payloads that need a broader
Java object surface than the portable xlang mapping. This includes ordinary Java objects, records,
enums, primitive and object arrays, common JDK collections and wrappers, interfaces, inheritance,
shared references, and circular object graphs.</p>
<p>Java native mode also supports classes that use JDK serialization hooks:</p>
<ul>
<li class=""><code>writeObject</code> and <code>readObject</code>;</li>
<li class=""><code>writeReplace</code> and <code>readResolve</code>;</li>
<li class=""><code>readObjectNoData</code>; and</li>
<li class=""><code>Externalizable</code>.</li>
</ul>
<p>Fory honors these hooks while writing Fory native bytes; it does not emit Java
<code>ObjectOutputStream</code> bytes. See <a class="" href=/docs/next/object-serialization/java/jdk-serialization>JDK Custom Serialization</a> for the exact
semantics.</p>
<p>Use Java native mode when replacing Java-only use of Kryo, FST, Hessian, or JDK serialization and
the existing Java object model should remain the serialization model.</p>
<h2 class="anchor anchorTargetStickyNavbar_Vzrq" id=python>Python<a href=#python class=hash-link aria-label="Direct link to Python" title="Direct link to Python" translate=no></a></h2>
<p>Choose <a class="" href=/docs/next/object-serialization/python/native>Python native serialization</a> for Python-only payloads that need Python
objects beyond the portable xlang surface. Native mode supports classes, global and local
functions, lambdas, closures, instance methods, class methods, static methods, shared references,
and circular object graphs.</p>
<p>It also supports Python object construction and state hooks, including:</p>
<ul>
<li class=""><code>__getstate__</code> and <code>__setstate__</code>;</li>
<li class=""><code>__getnewargs__</code> and <code>__getnewargs_ex__</code>; and</li>
<li class=""><code>__reduce__</code> and <code>__reduce_ex__</code>.</li>
</ul>
<p>Use it when replacing Pickle or cloudpickle for a Python-only object graph. It is also an option for
replacing a Python-only MessagePack boundary when both endpoints move to Fory and the application
wants to serialize Python objects directly. If MessagePack is currently used as a language-neutral
exchange format, use xlang instead.</p>
<p>See <a class="" href=/docs/next/object-serialization/python/functions-classes-methods>Functions, Classes, and Methods</a> and
<a class="" href=/docs/next/object-serialization/python/serialization-hooks>Serialization Hooks</a> for the supported Python object shapes and
reconstruction behavior.</p>
<h2 class="anchor anchorTargetStickyNavbar_Vzrq" id=rust>Rust<a href=#rust class=hash-link aria-label="Direct link to Rust" title="Direct link to Rust" translate=no></a></h2>
<p>Choose <a class="" href=/docs/next/object-serialization/rust/native>Rust native serialization</a> when every endpoint is Rust and the payload
should use the Rust-specific wire format. This choice does not mean common Rust containers,
<code>Rc&lt;T></code>, <code>Arc&lt;T></code>, trait objects, or <code>dyn Any</code> are unavailable in xlang. Those carriers can also
participate in xlang when their selected concrete types have portable mappings. Use the
<a class="" href=/docs/next/specification/xlang_type_mapping>Xlang Type Mapping</a> and the Rust language guide to check the
exact model.</p>
<p>One native-specific shape is a data-carrying, struct-style enum whose variants contain multiple
fields directly. In native mode, a <code>#[derive(ForyUnion)]</code> enum can mix unit variants, tuple variants
with one or more fields, and named variants with one or more fields:</p>
<div class="language-rust codeBlockContainer_Ckt0 theme-code-block" style=--prism-color:#393A34;--prism-background-color:#f6f8fa><div class=codeBlockContent_QJqH><pre tabindex=0 class="prism-code language-rust codeBlock_bY9V thin-scrollbar" style=color:#393A34;background-color:#f6f8fa><code class=codeBlockLines_e6Vv><div class=token-line style=color:#393A34><span class="token keyword" style=color:#00009f>use</span><span class="token plain"> </span><span class="token namespace" style=opacity:0.7>fory</span><span class="token namespace punctuation" style=opacity:0.7;color:#393A34>::</span><span class="token class-name">ForyUnion</span><span class="token punctuation" style=color:#393A34>;</span><span class="token plain"></span><br/></div><div class=token-line style=color:#393A34><span class="token plain" style=display:inline-block></span><br/></div><div class=token-line style=color:#393A34><span class="token plain"></span><span class="token attribute attr-name" style=color:#00a4db>#[derive(ForyUnion)]</span><span class="token plain"></span><br/></div><div class=token-line style=color:#393A34><span class="token plain"></span><span class="token keyword" style=color:#00009f>enum</span><span class="token plain"> </span><span class="token type-definition class-name">Command</span><span class="token plain"> </span><span class="token punctuation" style=color:#393A34>{</span><span class="token plain"></span><br/></div><div class=token-line style=color:#393A34><span class="token plain"> </span><span class="token attribute attr-name" style=color:#00a4db>#[fory(default)]</span><span class="token plain"></span><br/></div><div class=token-line style=color:#393A34><span class="token plain"> </span><span class="token class-name">Idle</span><span class="token punctuation" style=color:#393A34>,</span><span class="token plain"></span><br/></div><div class=token-line style=color:#393A34><span class="token plain"> </span><span class="token class-name">Move</span><span class="token punctuation" style=color:#393A34>(</span><span class="token keyword" style=color:#00009f>i32</span><span class="token punctuation" style=color:#393A34>,</span><span class="token plain"> </span><span class="token keyword" style=color:#00009f>i32</span><span class="token punctuation" style=color:#393A34>)</span><span class="token punctuation" style=color:#393A34>,</span><span class="token plain"></span><br/></div><div class=token-line style=color:#393A34><span class="token plain"> </span><span class="token class-name">Create</span><span class="token plain"> </span><span class="token punctuation" style=color:#393A34>{</span><span class="token plain"> id</span><span class="token punctuation" style=color:#393A34>:</span><span class="token plain"> </span><span class="token keyword" style=color:#00009f>u128</span><span class="token punctuation" style=color:#393A34>,</span><span class="token plain"> label</span><span class="token punctuation" style=color:#393A34>:</span><span class="token plain"> </span><span class="token class-name">String</span><span class="token plain"> </span><span class="token punctuation" style=color:#393A34>}</span><span class="token punctuation" style=color:#393A34>,</span><span class="token plain"></span><br/></div><div class=token-line style=color:#393A34><span class="token plain"></span><span class="token punctuation" style=color:#393A34>}</span><br/></div></code></pre></div></div>
<p>An xlang UNION alternative carries at most one declared payload value. Multiple logical fields must
be wrapped in an explicitly declared struct for xlang, while Rust native mode can encode the tuple
or named fields directly. See <a class="" href=/docs/next/object-serialization/rust/schema-evolution#enum-support>Rust Enum Support</a> and
<a class="" href=/docs/next/object-serialization/rust/external-types#native-struct-style-enums>External-Type Serialization</a> for local and
third-party enum shapes.</p>
<h2 class="anchor anchorTargetStickyNavbar_Vzrq" id=c>C++<a href=#c class=hash-link aria-label="Direct link to C++" title="Direct link to C++" translate=no></a></h2>
<p>Choose <a class="" href=/docs/next/object-serialization/cpp/native>C++ native serialization</a> when every endpoint is C++ and the data model
should use the C++-specific wire format. Standard containers, structs and classes,
<code>std::optional</code>, <code>std::variant</code>, tuple-like values, smart pointers, and supported scalar carriers
are not categorically native-only; they can also work in xlang when the corresponding portable
mapping exists.</p>
<p>Choose native mode because the boundary is C++-only or because the particular model needs a
C++-specific representation, not merely because it uses a C++ standard-library type. Use
<a class="" href=/docs/next/object-serialization/cpp/supported-types>Supported Types</a> for the exact native and xlang mappings.</p>
<h2 class="anchor anchorTargetStickyNavbar_Vzrq" id=migrating-from-another-serializer>Migrating From Another Serializer<a href=#migrating-from-another-serializer class=hash-link aria-label="Direct link to Migrating From Another Serializer" title="Direct link to Migrating From Another Serializer" translate=no></a></h2>
<p>Native mode is a replacement serialization path, not a decoder for another library's wire format.
Kryo, FST, Hessian, JDK serialization, Pickle, cloudpickle, and MessagePack bytes do not become Fory
native bytes automatically.</p>
<p>Move writers and readers to the corresponding Fory implementation family together. If existing
stored data must remain readable during migration, keep the previous decoder at that boundary and
reserialize values with Fory as they are migrated. Do not use native mode for a boundary that still
has readers using a different native wire format.</p>
<h2 class="anchor anchorTargetStickyNavbar_Vzrq" id=enable-native-mode>Enable Native Mode<a href=#enable-native-mode class=hash-link aria-label="Direct link to Enable Native Mode" title="Direct link to Enable Native Mode" translate=no></a></h2>
<table><thead><tr><th>Language<th>Native-mode configuration<tbody><tr><td>Java<td><code>Fory.builder().withXlang(false).build()</code><tr><td>Python<td><code>pyfory.Fory(xlang=False)</code><tr><td>C++<td><code>Fory::builder().xlang(false).build()</code><tr><td>Rust<td><code>Fory::builder().xlang(false).build()</code></table>
<h2 class="anchor anchorTargetStickyNavbar_Vzrq" id=language-guides>Language Guides<a href=#language-guides class=hash-link aria-label="Direct link to Language Guides" title="Direct link to Language Guides" translate=no></a></h2>
<ul>
<li class=""><a class="" href=/docs/next/object-serialization/java/native>Java</a></li>
<li class=""><a class="" href=/docs/next/object-serialization/python/native>Python</a></li>
<li class=""><a class="" href=/docs/next/object-serialization/cpp/native>C++</a></li>
<li class=""><a class="" href=/docs/next/object-serialization/go/native>Go</a></li>
<li class=""><a class="" href=/docs/next/object-serialization/rust/native>Rust</a></li>
<li class=""><a class="" href=/docs/next/object-serialization/scala/native>Scala</a></li>
<li class=""><a class="" href=/docs/next/object-serialization/kotlin/native>Kotlin</a></li>
</ul>
<p>Each language guide owns its exact supported types, configuration, schema behavior, extension APIs,
and diagnostics.</div><footer class="theme-doc-footer docusaurus-mt-lg"><div class="row margin-top--sm theme-doc-footer-edit-meta-row"><div class="col noPrint_WFHX"><a href=https://github.com/apache/fory-site/tree/main/docs/object-serialization/native.md target=_blank rel="noopener noreferrer" class=theme-edit-this-page><svg fill=currentColor height=20 width=20 viewBox="0 0 40 40" class=iconEdit_Z9Sw aria-hidden=true><g><path d="m34.5 11.7l-3 3.1-6.3-6.3 3.1-3q0.5-0.5 1.2-0.5t1.1 0.5l3.9 3.9q0.5 0.4 0.5 1.1t-0.5 1.2z m-29.5 17.1l18.4-18.5 6.3 6.3-18.4 18.4h-6.3v-6.2z"/></g></svg>Edit this page</a></div><div class="col lastUpdated_JAkA"></div></div></footer></article><nav class="docusaurus-mt-lg pagination-nav" aria-label="Docs pages"><a class="pagination-nav__link pagination-nav__link--prev" href=/docs/next/object-serialization/xlang><div class=pagination-nav__sublabel>Previous</div><div class=pagination-nav__label>Xlang Serialization</div></a><a class="pagination-nav__link pagination-nav__link--next" href=/docs/next/object-serialization/java/><div class=pagination-nav__sublabel>Next</div><div class=pagination-nav__label>Java Object Serialization</div></a></nav></div></div><div class="col col--3"><div class="tableOfContents_bqdL thin-scrollbar theme-doc-toc-desktop"><ul class="table-of-contents table-of-contents__left-border"><li><a href=#when-to-use-native-mode class="table-of-contents__link toc-highlight">When To Use Native Mode</a><li><a href=#java class="table-of-contents__link toc-highlight">Java</a><li><a href=#python class="table-of-contents__link toc-highlight">Python</a><li><a href=#rust class="table-of-contents__link toc-highlight">Rust</a><li><a href=#c class="table-of-contents__link toc-highlight">C++</a><li><a href=#migrating-from-another-serializer class="table-of-contents__link toc-highlight">Migrating From Another Serializer</a><li><a href=#enable-native-mode class="table-of-contents__link toc-highlight">Enable Native Mode</a><li><a href=#language-guides class="table-of-contents__link toc-highlight">Language Guides</a></ul></div></div></div></div></main></div></div></div><footer class="theme-layout-footer footer footer--dark"><div class="container container-fluid"><div class="row footer__links"><div class="theme-layout-footer-column col footer__col"><div class=footer__title>Community</div><ul class="footer__items clean-list"><li class=footer__item><a href=https://lists.apache.org/list.html?dev@fory.apache.org target=_blank rel="noopener noreferrer" class=footer__link-item>Mailing list<svg width=13.5 height=13.5 aria-label="(opens in new tab)" class=iconExternalLink_nPIU><use href=#theme-svg-external-link /></svg></a><li class=footer__item><a href=https://join.slack.com/t/fory-project/shared_invite/zt-1u8soj4qc-ieYEu7ciHOqA2mo47llS8A target=_blank rel="noopener noreferrer" class=footer__link-item>Slack<svg width=13.5 height=13.5 aria-label="(opens in new tab)" class=iconExternalLink_nPIU><use href=#theme-svg-external-link /></svg></a><li class=footer__item><a href=https://twitter.com/ApacheFory target=_blank rel="noopener noreferrer" class=footer__link-item>Twitter<svg width=13.5 height=13.5 aria-label="(opens in new tab)" class=iconExternalLink_nPIU><use href=#theme-svg-external-link /></svg></a></ul></div><div class="theme-layout-footer-column col footer__col"><div class=footer__title>Docs</div><ul class="footer__items clean-list"><li class=footer__item><a class=footer__link-item href=/docs/start/>Install</a><li class=footer__item><a class=footer__link-item href=/docs/start/>Usage</a><li class=footer__item><a class=footer__link-item href=/docs/benchmarks/>Benchmark</a></ul></div><div class="theme-layout-footer-column col footer__col"><div class=footer__title>Repositories</div><ul class="footer__items clean-list"><li class=footer__item><a href=https://github.com/apache/fory target=_blank rel="noopener noreferrer" class=footer__link-item>Apache Fory™<svg width=13.5 height=13.5 aria-label="(opens in new tab)" class=iconExternalLink_nPIU><use href=#theme-svg-external-link /></svg></a><li class=footer__item><a href=https://github.com/apache/fory-site target=_blank rel="noopener noreferrer" class=footer__link-item>Website<svg width=13.5 height=13.5 aria-label="(opens in new tab)" class=iconExternalLink_nPIU><use href=#theme-svg-external-link /></svg></a></ul></div></div><div class="footer__bottom text--center"><div class=margin-bottom--sm><a href=https://apache.org/ rel="noopener noreferrer" class=footerLogoLink_BH7S><img src=/img/asf_logo.svg alt="ASF Logo" class="footer__logo themedComponent_mlkZ themedComponent--light_NVdE" width=200 /><img src=/img/asf_logo.svg alt="ASF Logo" class="footer__logo themedComponent_mlkZ themedComponent--dark_xIcU" width=200 /></a></div><div class=footer__copyright><div>
<p>
Copyright © 2026 The Apache Software Foundation, Licensed under the Apache License, Version 2.0. <br/>
Apache Fory, Fory, Apache, the Apache Logo and the Apache Fory logo are either registered trademarks or trademarks of the Apache Software Foundation in the United States and/or other countries.
</p>
</div></div></div></div></footer></div></body>