Moshi and Gson JSON adapters fail for messages with a map<bool, V> field
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 70/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- kotlin
- Lĩnh vực
- backend-api-design
Hướng nghiên cứu
Bắt đầu bằng cách đọc JsonIntegration.mapKeyJsonFormatter() và fixture map_types.proto hiện có; issue nêu rõ phần xử lý ProtoAdapter.BOOL còn thiếu và kiểu khóa chưa được kiểm thử. Kiểm tra cách các JSON adapter định dạng và phân tích các khóa map khác, sau đó bổ sung kiểm thử cho khóa bool ở cả Moshi và Gson. Hoàn thành khi các khóa bool của map được tuần tự hóa thành "true" hoặc "false" và đọc lại thành công.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Kotlin
- Star
- 4.4k
- Fork
- 635
- Merge trung bình
- 7 giờ 27 phút
- Pull request đã merge (30 ngày)
- 2
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của square/wire
-
GrpcStreamingCall() factory's executeIn() hardcodes Dispatchers.IO instead of using an incoming scopeCó thể đã có người làm @oldergod đã nhận 197 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
Wire 7.1.0: Uncaught IllegalStateException on Incompatible Wire Types for Message FieldsCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
-
Swift: clear a field's preserved unknown enum value from unknownFields when the field is mutatedĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 52/100
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 76/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 55/100
Issue tương tự
-
OkHttp versions 5.4.0+ no longer include baseline-prof.txtCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởbug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 83/100
lysine-dev/okhttp#9828 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
ReadYouApp/ReadYou#1347 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
yschimke/compose-preview-contracts#210 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
📦 expo-device Android contributor: external needs review sdk-58 severity: low
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
expo/expo#52547 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
afk-ok area:data-quality importer size:S
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
enorm-labs/event-junkie#4221 ·
Maintainer thường phản hồi trong vòng 1 ngày