Serialization and deserialization of children
<p>Let's assume I have the following structure:</p>

<pre><code>abstract class foo{}
class bar1 extends foo{
     int demo1 = 0;
}
class bar2 extends foo{
     int demo1 = 0;
     int demo2 = 0;
}
class bar3 extends foo{}
</code></pre>

<p>Usually when I need to send a Json, I use the following code</p>

<pre><code>Gson gson = new Gson()
gson.toJson(bar1);
</code></pre>

<p><em>Recieving end</em></p>

<pre><code>Gson gson = new Gson()
bar1 test = gson.fromJson(gsonString, bar1);
</code></pre>

<p>The issue here is that I need to send bar1/bar2/bar3 and get back the original object - <strong>Meaning I don't know what the current JSON should be parsed back into</strong>. Another layer of complexity is added due to the fact that an array of bar1/bar2/bar3 are being sent back.</p>

<p>Ex: </p>

<pre><code>//Issue: is the second param bar1 bar2 or bar3?
//I put a questionmark where the issues occur, due to the fact 
//that I wouldn't know on the recieving side whether I'm going 
//to recieve bar1/bar2/bar3
? test = gson.fromJson(gsonString, ?);
</code></pre>

<p>I tried storing the type in foo, but without being able to parse it back there is no way to know the type.</p>