UPDATED
I found a problem using Gson library using nested classes. When Gson build the nested object leaves the reference of the inner class to the outer class this$0
to null
making any reference to the outer class produce an NullPointerException
(below a complete example). Is this known Gson issue with solution?
import com.google.gson.Gson;
public class Outer {
protected Inner inner = null;
public Inner getInner() {
return inner;
}
protected void something(){
}
public void function(){
inner.innerFunction();
}
public class Inner {
public String name = null;
protected void innerFunction(){
something();//exception source
}
}
public static void main(String[] args){
String str = "{\"inner\":{\"name\"=\"test\"}}";
Outer outer = (new Gson()).fromJson(str,Outer.class);
System.out.println(outer.getInner().name);
outer.function(); // exception here
}
}