JSON generated from Swift message with >=16 fields exposes `storage` field
Open
@efirestone is already working on this.
Since Jul 30, 2021.
bug
lang/swift
- Dominant language
- Kotlin
- Stars
- 4.4k
- Forks
- 627
- Avg merge
- 3d 15m
- Merged PRs (30d)
- 20
Description
Using this protobuf message:
message ManyFields {
int32 field_1 = 1;
int32 field_2 = 2;
int32 field_3 = 3;
int32 field_4 = 4;
int32 field_5 = 5;
int32 field_6 = 6;
int32 field_7 = 7;
int32 field_8 = 8;
int32 field_9 = 9;
int32 field_10 = 10;
int32 field_11 = 11;
int32 field_12 = 12;
int32 field_13 = 13;
int32 field_14 = 14;
int32 field_15 = 15;
int32 field_16 = 16;
int32 field_17 = 17;
int32 field_18 = 18;
}
Then create and object and encode to json (similar than in your JsonLitmusTest.swift):
let manyFieldsWire: ManyFields = ManyFields(
field_1: 1, field_2: 2, field_3: 3, field_4: 4, field_5: 5, field_6: 6, field_7: 7,
field_8: 8, field_9: 9, field_10: 10, field_11: 11, field_12: 12, field_13: 13,
field_14: 14, field_15: 15, field_16: 16, field_17: 17, field_18: 18 )
// Serialize to JSON
let manyFieldsJsonWireData = try! JSONEncoder().encode(manyFieldsWire)
let manyFieldsJsonWire = String(data: manyFieldsJsonWireData, encoding: .utf8)!
print("manyFields JSON Wire:\n" + manyFieldsJsonWire)
}
Produces the following JSON:
{
"storage": {
"field_14": 14,
"field_5": 5,
"field_15": 15,
"field_2": 2,
"field_7": 7,
"field_10": 10,
"field_16": 16,
"field_4": 4,
"field_11": 11,
"field_9": 9,
"field_17": 17,
"field_1": 1,
"field_6": 6,
"field_12": 12,
"field_18": 18,
"field_13": 13,
"field_3": 3,
"field_8": 8
}
}
As you can see there's a top-level storage in the JSON that in my opinion shouldn't be exposed.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.