Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta Adatta ai principianti
#3,732 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@auraseb ci sta già lavorando.

Dal 19/10/2026.

  • #3733 di @auraseb — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
70/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
kotlin

Direzione di ricerca

Inizia leggendo JsonIntegration.mapKeyJsonFormatter() e il fixture map_types.proto esistente; l’issue segnala la gestione mancante di ProtoAdapter.BOOL e il tipo di chiave non coperto. Controlla come gli adapter JSON formattano e analizzano le altre chiavi delle map, quindi aggiungi la copertura per le chiavi bool sia per Moshi sia per Gson. Il lavoro è completato quando le chiavi bool delle map vengono serializzate come "true" o "false" e rilette correttamente.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Kotlin
Stelle
4.4k
Fork
634
Merge medio
1g 21h
PR unite (30g)
5

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di square/wire

Tutte le issue di square/wire

Issue simili

Altre issue su Kotlin

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.