Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Moshi and Gson JSON adapters fail for messages with a map<bool, V> field

オープン 初心者向け
#3,732 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@sebxt がすでに取り組んでいます。

2026年10月19日 から。

  • #3733 @sebxt による — オープン

評価

難易度
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

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

square/wire のほかの issue

square/wire の issue をすべて見る

似ている issue

Kotlin の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。