title: Cast a hexadecimal string to a class object
body: <p>I have a class like this:</p>
  
  <pre><code>public class Fields implements java.io.Serializable{
      public short ID;
      public int SSN;
      public long Number;
  }
  </code></pre>
  
  <p>and I have a hexadecimal string with the value like this which each 2 characters is representative of a byte:</p>
  
  <pre><code>String str="1000180018000540AC80D6487653E5000100D40B7900D4C3FFF2FAFF8985";
  </code></pre>
  
  <p>Now I want to cast this string to the above class object in a schema like this:</p>
  
  <pre><code>//ID has short type so we need 2 bytes
  ID=4096; //(decimal value of 1000)
  
  //SSN has integer type so we need 4 bytes
  SSN=402659328; //(decimal value of 18001800)
  
  //Number has long type so we need 8 bytes
  Number=378492038049986131; //(decimal value of 0540AC80D6487653)
  </code></pre>
  
  <p>This casting can be implemented in c++ with <code>&lt;reinterpret_cast&gt;</code> so easily but as the <a href="https://stackoverflow.com/questions/4805058/is-there-cast-in-java-similar-to-reinterpret-cast-in-c">Is there cast in Java similar to  in C++</a> question is said, I can implement that with serialization in java. I think serialization can be used when we serialize a class object to the byte arrays at first and second we can de-serialize the obtained bytes to the primitive class object, which is different from my propose a little, because I have a string (like bytes) which I want to de-serialize that. So how can I do that?</p>