From e5cfe139bcdfd24c898be1c7320b3d584243f7ff Mon Sep 17 00:00:00 2001 From: Tony Liao Date: Mon, 13 Jul 2026 17:01:48 -0700 Subject: [PATCH] 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`: ``` @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 --- .../java/com/google/protobuf/util/JsonFormatTest.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java b/java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java index 86a13419f7..f3a62a0e16 100644 --- a/java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java +++ b/java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java @@ -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();