title: How to serialize/deserialize Java Object[] correctly?
body: <p>I am writing an rpc framework, but facing a problem about serialization.</p>
  
  <p>You know to translate Request between client and server, I should have a Request class like that:</p>
  
  <pre><code>class Request {
      // target service class
      private Class&lt;?&gt; targetService;
      // target service method
      private String targetMethod;
      // target method param types
      private Class&lt;?&gt;[] targetParamTypes;
      // the params
      private Object[] targetParams;
      // getters &amp; setters &amp; contructors
  }
  </code></pre>
  
  <p>But:</p>
  
  <ol>
  <li><p>for the <code>targetParams</code> field, if I use Gson as serialization tool, it will get <code>com.google.gson.internal.LinkedTreeMap cannot be cast to the.packages.to.MyClass</code> error if I put POJOs into <code>targetParams</code>, for the generic problem.</p></li>
  <li><p>for <code>int</code> class, Gson always parse it as a <code>Double</code>, so I cannot use <code>targetParamTypes[i].cast(targetParams[i])</code> to force cast it to Integer(Double cannot be casted to Integer), it sucks...</p></li>
  </ol>
  
  <p>So anybody have the solution to solve the problem? How to make the serialize/deserialize steps fast and accurate? Or any tools recommanded?</p>
  
  <p>I have tried:</p>
  
  <ul>
  <li>Gson, get the problems before</li>
  <li>Kyro, the codec system sucks, I have no idea how to serialize/deserialize a HashMap...</li>
  <li>protostuff, ummmm, it not support Java 9+, my env is Java 11, SUCK!</li>
  </ul>
  
  <p>So any advice?</p>