[I] [Question] Problem with Fury Serialization/Deserialization for Nested Classes [fury]</span></a></span> </h1> <p class="darkgray font13"> <span class="sender pipe"><a href="/search?l=commits@fury.apache.org&q=from:%22via+GitHub%22" rel="nofollow"><span itemprop="author" itemscope itemtype="http://schema.org/Person"><span itemprop="name">via GitHub</span></span></a></span> <span class="date"><a href="/search?l=commits@fury.apache.org&q=date:20241020" rel="nofollow">Sun, 20 Oct 2024 19:38:54 -0700</a></span> </p> </div> <div itemprop="articleBody" class="msgBody"> <!--X-Body-of-Message--> <pre> Moouna opened a new issue, #1893: URL: <a rel="nofollow" href="https://github.com/apache/fury/issues/1893">https://github.com/apache/fury/issues/1893</a></pre><pre> ### Question ### Problem with Fury Serialization/Deserialization for Nested Classes I’m using **Fury** for serializing and deserializing two different classes (`Source` and `Target`) that have similar structures but different inner classes (`SourceInner` and `TargetInner`). Serialization works when handling a list (`innerList`), but it fails when serializing a single field (`inner`), throwing a `ClassCastException`. ### Classes: ```java @Data public class Source { private SourceInner inner; private List<SourceInner> innerList; } public class SourceInner { } @Data public class Target { private TargetInner inner; private List<TargetInner> innerList; } public class TargetInner { } ``` ### Test Case 1: Success Serialization and deserialization works fine when using the `innerList` field (a list of `SourceInner`): ```java @Test public void testFurySuccess() { Source source = new Source(); source.setInnerList(new ArrayList<>()); source.getInnerList().add(new SourceInner()); Fury fury = Fury.builder() .withLanguage(Language.JAVA) .requireClassRegistration(false) .withClassVersionCheck(false) .withCodegen(true) .withJdkClassSerializableCheck(false) .build(); byte[] bytes = fury.serializeJavaObject(source); Target target = fury.deserializeJavaObject(bytes, Target.class); System.out.println(target); // Success } ``` ### Test Case 2: Failure However, when trying to serialize the `inner` field (a single instance of `SourceInner`), it fails with a `ClassCastException`: ```java @Test public void testFuryFailed() { Source source = new Source(); source.setInner(new SourceInner()); Fury fury = Fury.builder() .withLanguage(Language.JAVA) .requireClassRegistration(false) .withClassVersionCheck(false) .withCodegen(true) .withJdkClassSerializableCheck(false) .build(); byte[] bytes = fury.serializeJavaObject(source); Target target = fury.deserializeJavaObject(bytes, Target.class); // Fails System.out.println(target); } ``` ### Error: ``` java.lang.ClassCastException: SourceInner cannot be cast to TargetInner at org.apache.fury.format.dto.TargetFuryCodec_0.read(TargetFuryCodec_0.java:242) at org.apache.fury.Fury.readDataInternal(Fury.java:958) at org.apache.fury.Fury.deserializeJavaObject(Fury.java:1117) ... ``` ### Question: How can I make Fury correctly deserialize `SourceInner` to `TargetInner` without a `ClassCastException`? Is there a way to map `SourceInner` to `TargetInner` automatically, or do I need to implement custom logic? Thanks in advance for any suggestions! -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@fury.apache.org.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@fury.apache.org For additional commands, e-mail: commits-h...@fury.apache.org </pre> </div> <div class="msgButtons margintopdouble"> <ul class="overflow"> <li class="msgButtonItems"><a class="button buttonleft " accesskey="p" href="msg05701.html">Previous message</a></li> <li class="msgButtonItems textaligncenter"><a class="button" accesskey="c" href="index.html#05723">View by thread</a></li> <li class="msgButtonItems textaligncenter"><a class="button" accesskey="i" href="maillist.html#05723">View by date</a></li> <li class="msgButtonItems textalignright"><a class="button buttonright " accesskey="n" href="msg05724.html">Next message</a></li> </ul> </div> <a name="tslice"></a> <div class="tSliceList margintopdouble"> <ul class="icons monospace"> <li class="icons-email tSliceCur"><span class="subject">[I] [Question] <title> Problem with Fury Serialization/De...</span> <span class="sender italic">via GitHub</span></li> <li><ul> <li class="icons-email"><span class="subject"><a href="msg05724.html">Re: [I] [Question] Problem with Fury Serialization/Deseria...</a></span> <span class="sender italic">via GitHub</span></li> <li class="icons-email"><span class="subject"><a href="msg05725.html">Re: [I] [Question] Problem with Fury Serialization/Deseria...</a></span> <span class="sender italic">via GitHub</span></li> <li class="icons-email"><span class="subject"><a href="msg05759.html">Re: [I] [Question] Problem with Fury Serialization/Deseria...</a></span> <span class="sender italic">via GitHub</span></li> <li class="icons-email"><span class="subject"><a href="msg05760.html">Re: [I] [Question] Problem with Fury Serialization/Deseria...</a></span> <span class="sender italic">via GitHub</span></li> </ul> </ul> </div> <div class="overflow msgActions margintopdouble"> <div class="msgReply" > <h2> Reply via email to </h2> <form method="POST" action="/mailto.php"> <input type="hidden" name="subject" value="[I] [Question] <title> Problem with Fury Serialization/Deserialization for Nested Classes [fury]"> <input type="hidden" name="msgid" value="I_kwDOJcVKYc6bCe_W@gitbox.apache.org"> <input type="hidden" name="relpath" value="commits@fury.apache.org/msg05723.html"> <input type="submit" value=" via GitHub "> </form> </div> </div> </div> <div class="aside" role="complementary"> <div class="logo"> <a href="/"><img src="/logo.png" width=247 height=88 alt="The Mail Archive"></a> </div> <form class="overflow" action="/search" method="get"> <input type="hidden" name="l" value="commits@fury.apache.org"> <label class="hidden" for="q">Search the site</label> <input class="submittext" type="text" id="q" name="q" placeholder="Search commits"> <input class="submitbutton" name="submit" type="image" src="/submit.png" alt="Submit"> </form> <div class="nav margintop" id="nav" role="navigation"> <ul class="icons font16"> <li class="icons-home"><a href="/">The Mail Archive home</a></li> <li class="icons-list"><a href="/commits@fury.apache.org/">commits - all messages</a></li> <li class="icons-about"><a href="/commits@fury.apache.org/info.html">commits - about the list</a></li> <li class="icons-expand"><a href="/search?l=commits@fury.apache.org&q=subject:%22%5C%5BI%5C%5D+%5C%5BQuestion%5C%5D+%3Ctitle%3E+Problem+with+Fury+Serialization%5C%2FDeserialization+for+Nested+Classes+%5C%5Bfury%5C%5D%22&o=newest&f=1" title="e" id="e">Expand</a></li> <li class="icons-prev"><a href="msg05701.html" title="p">Previous message</a></li> <li class="icons-next"><a href="msg05724.html" title="n">Next message</a></li> </ul> </div> <div class="listlogo margintopdouble"> </div> <div class="margintopdouble"> </div> </div> </div> <div class="footer" role="contentinfo"> <ul> <li><a href="/">The Mail Archive home</a></li> <li><a href="/faq.html#newlist">Add your mailing list</a></li> <li><a href="/faq.html">FAQ</a></li> <li><a href="/faq.html#support">Support</a></li> <li><a href="/faq.html#privacy">Privacy</a></li> <li class="darkgray">I_kwDOJcVKYc6bCe_W@gitbox.apache.org</li> </ul> </div> </body> </html> <script>(function(){function c(){var b=a.contentDocument||a.contentWindow.document;if(b){var d=b.createElement('script');d.innerHTML="window.__CF$cv$params={r:'9d2f3b99793b1ec6',t:'MTc3MTkzODkzNw=='};var a=document.createElement('script');a.src='/cdn-cgi/challenge-platform/scripts/jsd/main.js';document.getElementsByTagName('head')[0].appendChild(a);";b.getElementsByTagName('head')[0].appendChild(d)}}if(document.body){var a=document.createElement('iframe');a.height=1;a.width=1;a.style.position='absolute';a.style.top=0;a.style.left=0;a.style.border='none';a.style.visibility='hidden';document.body.appendChild(a);if('loading'!==document.readyState)c();else if(window.addEventListener)document.addEventListener('DOMContentLoaded',c);else{var e=document.onreadystatechange||function(){};document.onreadystatechange=function(b){e(b);'loading'!==document.readyState&&(document.onreadystatechange=e,c())}}}})();</script>