GSON deserialize Object by its field names
<p>Lets assume we have this json:</p>

<pre><code>{
 "id": 1,
 "first_name": "name"
 "studentId": "1235234"
}
</code></pre>

<p>I know I can deserialize this with GSON by making Class like this:</p>

<pre><code>class Student {
  int id;
  String first_name;
  String studentId;
}
</code></pre>

<p>Is there a way to achieve the same results by using two classes, ie.</p>

<pre><code>class User {
   int id;
   String first_name;
}

class Student {
   User user;
   String studentId;
}
</code></pre>

<p>Is there a way to specify with some annotation to GSON so that it knows how populate 'user' object, except by Student class extending User class?</p>

<p><strong>UPDATE</strong>:</p>

<p>1) Thanks for suggestion with extending, but I forgot to mention that I can't extend the 'User' (don't ask why :)), so thats why I'm looking for a workaround in a first place.</p>

<p>2) Custom deserializer would do the job, but I have multiple classes that have 'User' inside, so that would mean a lot of added classes and I also want to avoid that.</p>

<p>Thanks in advance,
Milos</p>