そのため、 FUNF プロジェクトで見つけたこのbundletypeadapterを実装することにより、gson を使用してバンドル オブジェクトを json に変換しようとしていました。
私の問題は、そのコードブロックを適切に実装する方法が完全にわからないことです。現在私にとって意味のある唯一の方法は、循環依存関係になります。
新しい TypeAdapter を通常どのように実装するか:
...
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(Location.class, new LocationDeserializer());
gsonBuilder.registerTypeAdapter(Location.class, new LocationSerializer());
Gson gson = gsonBuilder.create();
...
または、この場合に私が期待すること:
...
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(Bundle.class, new BundleTypeAdapter());
Gson gson = gsonBuilder.create();
...
私の問題は、 BundleTypeAdapter が持つ唯一のコンストラクターが BundleTypeAdapter(Gson gson) であり、まだ作成またはインスタンス化していないオブジェクトを渡す方法がよくわからないことです...
何か案は?