Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
ケース クラスと JSON で異なる名前のフィールドを使用したいので、エンコードとデコードの両方で快適に名前を変更する方法が必要です。
誰かが良い解決策を持っていますか?
Encoderの関数を使用してmapJson、一般的なものからエンコーダーを派生させ、フィールド名を再マップできます。
mapJson
また、Decoder の関数を使用しprepareて、渡された JSON を汎用 Decoder に変換できます。
prepare
両方をゼロから作成することもできますが、大量のボイラープレートになる可能性があります。これらのソリューションは両方とも最大数行にする必要があります。