mirror of
https://github.com/protocolbuffers/protobuf
synced 2026-08-26 02:23:14 -04:00
New unittest case to validate Java parseJson behavior with 1-element arrays.
In Java, it seems like the existing behavior is that we allow
single-element arrays to be parsed into a non-repeated field.
In `public final class JsonArray extends JsonElement implements Iterable<JsonElement>`:
```
@Override
public String getAsString() {
return getAsSingleElement().getAsString();
}
```
TBH I don't know if this behavior is necessarily _desired_, but here is
a unit test to validate this behavior so that we don't accidentally
break it without intending to.
PiperOrigin-RevId: 947320631
This commit is contained in:
parent
9b0d074ea6
commit
e5cfe139bc
1 changed files with 10 additions and 0 deletions
|
|
@ -1963,6 +1963,16 @@ public class JsonFormatTest {
|
|||
assertThat(actualBuilder.build()).isEqualTo(expected);
|
||||
}
|
||||
|
||||
// TODO: b/534418787 - Investigate this behavior further, especially in conformance tests.
|
||||
@Test
|
||||
public void testParserSingleElementArrayForNonRepeatedEnum() throws Exception {
|
||||
TestAllTypes.Builder actualBuilder = TestAllTypes.newBuilder();
|
||||
mergeFromJson("{\"optionalNestedEnum\": [\"FOO\"]}", actualBuilder);
|
||||
|
||||
TestAllTypes expected = TestAllTypes.newBuilder().setOptionalNestedEnum(NestedEnum.FOO).build();
|
||||
assertThat(actualBuilder.build()).isEqualTo(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomJsonName() throws Exception {
|
||||
TestCustomJsonName message = TestCustomJsonName.newBuilder().setValue(12345).build();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue