Я хочу передать объект в связку. Теперь я сделал преобразование в объект Json с помощью GSON.
Пакет передан, пакет имеет правильное строковое представление, но когда я создаю объект из строки, я получаю огромную ошибку.
FATAL EXCEPTION: main
java.lang.RuntimeException: Failed to invoke private android.net.Uri() with no args
at com.google.gson.internal.ConstructorConstructor$3.construct(ConstructorConstructor.java:107)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:162)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:93)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:172)
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:40)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:81)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:60)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:93)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:172)
at com.google.gson.Gson.fromJson(Gson.java:803)
at com.google.gson.Gson.fromJson(Gson.java:768)
at com.google.gson.Gson.fromJson(Gson.java:717)
at com.google.gson.Gson.fromJson(Gson.java:689)
at com.test.fragment.QFragment.onCreateView(QFragment.java:54)
at android.app.Fragment.performCreateView(Fragment.java:1788)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:899)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1101)
at android.app.BackStackRecord.run(BackStackRecord.java:688)
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1559)
at android.app.FragmentManagerImpl$1.run(FragmentManager.java:445)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:5789)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:843)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.InstantiationException: can't instantiate class android.net.Uri
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at com.google.gson.internal.ConstructorConstructor$3.construct(ConstructorConstructor.java:104)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:162)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:93)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:172)
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:40)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:81)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:60)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:93)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:172)
at com.google.gson.Gson.fromJson(Gson.java:803)
at com.google.gson.Gson.fromJson(Gson.java:768)
at com.google.gson.Gson.fromJson(Gson.java:717)
at com.google.gson.Gson.fromJson(Gson.java:689)
at com.test.fragment.QFragment.onCreateView(QFragment.java:54)
at android.app.Fragment.performCreateView(Fragment.java:1788)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:899)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1101)
at android.app.BackStackRecord.run(BackStackRecord.java:688)
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1559)
at android.app.FragmentManagerImpl$1.run(FragmentManager.java:445)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:5789)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:843)
at dalvik.system.NativeStart.main(Native Method)
Я делаю преобразование следующим образом:
public static QFragment newInstance(FModel oModel) {
QFragment fragment = new QFragment();
fragment.mOModel = oModel;
Bundle bdl = new Bundle();
bdl.putString("oModel", new Gson().toJson(oModel));
fragment.setArguments(bdl);
return fragment;
}
и в моем фрагменте на createView:
String jsonMyObject = null;
Bundle args = this.getArguments();
if (args != null) {
jsonMyObject = args.getString("oModel");
}
mOrderModel = new Gson().fromJson(jsonMyObject, FModel.class);
Как лучше всего это исправить? Должен ли я меняться на сериализуемый или произвольный?