Here explained deserialization for classes with Generic types https://stackoverflow.com/a/8829656/4553806. Now suppese we I have some situation, but my Class has two constructors with different count of parameters.
class TestClass(val par1:String, val par2:String)
class TestClass(val par1:String)
So I know that my object is type of TestClass, but I don't know with which constructor it initialized.
How to deserialize?
Using this way
val fooType = object : TypeToken<Myclass<String>>() {}.type;
gson.fromJson(json, fooType);
or this
val fooType = object : TypeToken<Myclass<String, String>>() {}.type);
gson.fromJson(json, fooType);
could cause exception if objects fields count doesn't match.
If any one has experience with this case, please mention it here.