0
存在我的模型是這樣GSON更改默認布爾值false,如果該字段不以JSON
public class testModel {
public boolean a = true;
public Test2 test2 = new Test2();
public class Test2 {
public boolean b = true;
}
}
像這樣
{
"test2":{}
}
一個JSON當我解析此JSON與GSON
testModel testModel = new Gson().fromJson("{ \"test2\":{}}", testModel.class);
Log.e("test", testModel.a + " " + testModel.test2.b);
和日誌是:
E/test: true false
testModel.a爲'true',但testmodel.test2.b爲'false' 爲什麼Gson在b中不存在json時改變了b的默認值? b和a有什麼區別?
這是一個Gson的bug?
不,我只是自己測試過a和b都是假的 –
@SamuelRobert你的Gson版本是什麼? –
「2.8.0」版本; 'com.google.code.gson:gson:2.8.0' –