Moshi and Gson JSON adapters fail for messages with a map<bool, V> field
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 70/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- kotlin
調査の方向性
まず JsonIntegration.mapKeyJsonFormatter() と既存の map_types.proto フィクスチャを読みます。issue では、ProtoAdapter.BOOL の処理が不足していることと、キー型がテスト対象になっていないことが指摘されています。JSON アダプターが他の map キーをどのようにフォーマットして解析するかを確認し、Moshi と Gson の両方で bool キーのテストを追加します。bool map キーが "true" または "false" としてシリアライズされ、正常に読み戻せれば完了です。
索引モデルが issue の本文から書いたものです。
説明
What happens
Any message that has a map field with a bool key cannot be used with WireJsonAdapterFactory (Moshi) or WireTypeAdapterFactory (Gson). Building the adapter throws, even when the map is empty:
java.lang.IllegalStateException: Unexpected map key type: class kotlin.Boolean
at com.squareup.wire.internal.JsonIntegration.mapKeyJsonFormatter(JsonIntegration.kt)
What should happen
bool is a valid map key type in proto2 and proto3, and the schema accepts it. The proto3 JSON mapping encodes map keys as strings, so a bool key is written as "true" or "false" and read back from those strings.
Repro
syntax = "proto3";
message MapBoolKeys {
map<bool, string> map_bool_string = 1;
}
val moshi = Moshi.Builder().add(WireJsonAdapterFactory()).build()
val value = MapBoolKeys(map_bool_string = mapOf(true to "yes", false to "no"))
moshi.adapter(MapBoolKeys::class.java).toJson(value) // throws IllegalStateException
The same happens with Gson through WireTypeAdapterFactory.
Root cause
JsonIntegration.mapKeyJsonFormatter() handles STRING and every integer key adapter but has no branch for ProtoAdapter.BOOL, so it falls through to error("Unexpected map key type: ..."). The existing map_types.proto fixture covers all key types except bool.
- 主要言語
- Kotlin
- スター
- 4.4k
- フォーク
- 634
- 平均マージ
- 1日 21時間
- マージ済み PR(30日)
- 5
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
square/wire のほかの issue
-
GrpcStreamingCall() factory's executeIn() hardcodes Dispatchers.IO instead of using an incoming scope対応中かも @oldergod が 189 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
Swift: clear a field's preserved unknown enum value from unknownFields when the field is mutatedオープン
難易度 4/5 3〜5日 初心者へのやさしさ 52/100
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 55/100
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
enhancement impact:U1 P3 reach:R2 size:S
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 73/100
ankidroid/Anki-Android#22677 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
yschimke/homeassistant-remotecompose#1038 ·
メンテナーはふだん 1 日以内に返信
-
area:data-quality importer size:S
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
enorm-labs/event-junkie#3707 ·
メンテナーはふだん 1 日以内に返信
-
area/ui priority/p2 type/bug
難易度 1/5 1時間未満 初心者へのやさしさ 94/100
メンテナーはふだん 1 日以内に返信