31 package com.google.protobuf.util;
67 import java.io.IOException;
68 import java.io.InputStream;
69 import java.io.InputStreamReader;
70 import java.io.Reader;
71 import java.io.StringReader;
72 import java.math.BigDecimal;
73 import java.math.BigInteger;
74 import java.util.Collections;
75 import java.util.HashSet;
76 import java.util.Locale;
78 import junit.framework.TestCase;
83 Locale.setDefault(Locale.forLanguageTag(
"hi-IN"));
87 builder.setOptionalInt32(1234);
88 builder.setOptionalInt64(1234567890123456789L);
89 builder.setOptionalUint32(5678);
90 builder.setOptionalUint64(2345678901234567890L);
91 builder.setOptionalSint32(9012);
92 builder.setOptionalSint64(3456789012345678901L);
93 builder.setOptionalFixed32(3456);
94 builder.setOptionalFixed64(4567890123456789012L);
95 builder.setOptionalSfixed32(7890);
96 builder.setOptionalSfixed64(5678901234567890123L);
97 builder.setOptionalFloat(1.5
f);
98 builder.setOptionalDouble(1.25);
99 builder.setOptionalBool(
true);
100 builder.setOptionalString(
"Hello world!");
101 builder.setOptionalBytes(
ByteString.copyFrom(
new byte[] {0, 1, 2}));
102 builder.setOptionalNestedEnum(NestedEnum.BAR);
103 builder.getOptionalNestedMessageBuilder().setValue(100);
105 builder.addRepeatedInt32(1234);
106 builder.addRepeatedInt64(1234567890123456789L);
107 builder.addRepeatedUint32(5678);
108 builder.addRepeatedUint64(2345678901234567890L);
109 builder.addRepeatedSint32(9012);
110 builder.addRepeatedSint64(3456789012345678901L);
111 builder.addRepeatedFixed32(3456);
112 builder.addRepeatedFixed64(4567890123456789012L);
113 builder.addRepeatedSfixed32(7890);
114 builder.addRepeatedSfixed64(5678901234567890123L);
115 builder.addRepeatedFloat(1.5
f);
116 builder.addRepeatedDouble(1.25);
117 builder.addRepeatedBool(
true);
118 builder.addRepeatedString(
"Hello world!");
119 builder.addRepeatedBytes(
ByteString.copyFrom(
new byte[] {0, 1, 2}));
120 builder.addRepeatedNestedEnum(NestedEnum.BAR);
121 builder.addRepeatedNestedMessageBuilder().setValue(100);
123 builder.addRepeatedInt32(234);
124 builder.addRepeatedInt64(234567890123456789L);
125 builder.addRepeatedUint32(678);
126 builder.addRepeatedUint64(345678901234567890L);
127 builder.addRepeatedSint32(012);
128 builder.addRepeatedSint64(456789012345678901L);
129 builder.addRepeatedFixed32(456);
130 builder.addRepeatedFixed64(567890123456789012L);
131 builder.addRepeatedSfixed32(890);
132 builder.addRepeatedSfixed64(678901234567890123L);
133 builder.addRepeatedFloat(11.5
f);
134 builder.addRepeatedDouble(11.25);
135 builder.addRepeatedBool(
true);
136 builder.addRepeatedString(
"ello world!");
137 builder.addRepeatedBytes(
ByteString.copyFrom(
new byte[] {1, 2}));
138 builder.addRepeatedNestedEnum(NestedEnum.BAZ);
139 builder.addRepeatedNestedMessageBuilder().setValue(200);
151 Message parsedMessage = builder.build();
175 TestAllTypes.Builder builder = TestAllTypes.newBuilder();
177 TestAllTypes
message = builder.build();
181 +
" \"optionalInt32\": 1234,\n"
182 +
" \"optionalInt64\": \"1234567890123456789\",\n"
183 +
" \"optionalUint32\": 5678,\n"
184 +
" \"optionalUint64\": \"2345678901234567890\",\n"
185 +
" \"optionalSint32\": 9012,\n"
186 +
" \"optionalSint64\": \"3456789012345678901\",\n"
187 +
" \"optionalFixed32\": 3456,\n"
188 +
" \"optionalFixed64\": \"4567890123456789012\",\n"
189 +
" \"optionalSfixed32\": 7890,\n"
190 +
" \"optionalSfixed64\": \"5678901234567890123\",\n"
191 +
" \"optionalFloat\": 1.5,\n"
192 +
" \"optionalDouble\": 1.25,\n"
193 +
" \"optionalBool\": true,\n"
194 +
" \"optionalString\": \"Hello world!\",\n"
195 +
" \"optionalBytes\": \"AAEC\",\n"
196 +
" \"optionalNestedMessage\": {\n"
197 +
" \"value\": 100\n"
199 +
" \"optionalNestedEnum\": \"BAR\",\n"
200 +
" \"repeatedInt32\": [1234, 234],\n"
201 +
" \"repeatedInt64\": [\"1234567890123456789\", \"234567890123456789\"],\n"
202 +
" \"repeatedUint32\": [5678, 678],\n"
203 +
" \"repeatedUint64\": [\"2345678901234567890\", \"345678901234567890\"],\n"
204 +
" \"repeatedSint32\": [9012, 10],\n"
205 +
" \"repeatedSint64\": [\"3456789012345678901\", \"456789012345678901\"],\n"
206 +
" \"repeatedFixed32\": [3456, 456],\n"
207 +
" \"repeatedFixed64\": [\"4567890123456789012\", \"567890123456789012\"],\n"
208 +
" \"repeatedSfixed32\": [7890, 890],\n"
209 +
" \"repeatedSfixed64\": [\"5678901234567890123\", \"678901234567890123\"],\n"
210 +
" \"repeatedFloat\": [1.5, 11.5],\n"
211 +
" \"repeatedDouble\": [1.25, 11.25],\n"
212 +
" \"repeatedBool\": [true, true],\n"
213 +
" \"repeatedString\": [\"Hello world!\", \"ello world!\"],\n"
214 +
" \"repeatedBytes\": [\"AAEC\", \"AQI=\"],\n"
215 +
" \"repeatedNestedMessage\": [{\n"
216 +
" \"value\": 100\n"
218 +
" \"value\": 200\n"
220 +
" \"repeatedNestedEnum\": [\"BAR\", \"BAZ\"]\n"
229 TestAllTypes.newBuilder()
230 .setOptionalNestedEnumValue(12345)
231 .addRepeatedNestedEnumValue(12345)
232 .addRepeatedNestedEnumValue(0)
236 +
" \"optionalNestedEnum\": 12345,\n"
237 +
" \"repeatedNestedEnum\": [12345, \"FOO\"]\n"
242 TestMap.Builder mapBuilder = TestMap.newBuilder();
243 mapBuilder.putInt32ToEnumMapValue(1, 0);
244 mapBuilder.putInt32ToEnumMapValue(2, 12345);
245 TestMap mapMessage = mapBuilder.build();
248 +
" \"int32ToEnumMap\": {\n"
249 +
" \"1\": \"FOO\",\n"
259 TestAllTypes.newBuilder()
260 .addRepeatedFloat(
Float.NaN)
261 .addRepeatedFloat(
Float.POSITIVE_INFINITY)
262 .addRepeatedFloat(
Float.NEGATIVE_INFINITY)
263 .addRepeatedDouble(
Double.NaN)
264 .addRepeatedDouble(
Double.POSITIVE_INFINITY)
265 .addRepeatedDouble(
Double.NEGATIVE_INFINITY)
269 +
" \"repeatedFloat\": [\"NaN\", \"Infinity\", \"-Infinity\"],\n"
270 +
" \"repeatedDouble\": [\"NaN\", \"Infinity\", \"-Infinity\"]\n"
278 TestAllTypes.Builder builder = TestAllTypes.newBuilder();
281 +
" \"optionalInt32\": \"1234\",\n"
282 +
" \"optionalUint32\": \"5678\",\n"
283 +
" \"optionalSint32\": \"9012\",\n"
284 +
" \"optionalFixed32\": \"3456\",\n"
285 +
" \"optionalSfixed32\": \"7890\",\n"
286 +
" \"optionalFloat\": \"1.5\",\n"
287 +
" \"optionalDouble\": \"1.25\",\n"
288 +
" \"optionalBool\": \"true\"\n"
291 TestAllTypes
message = builder.build();
292 assertEquals(1234,
message.getOptionalInt32());
293 assertEquals(5678,
message.getOptionalUint32());
294 assertEquals(9012,
message.getOptionalSint32());
295 assertEquals(3456,
message.getOptionalFixed32());
296 assertEquals(7890,
message.getOptionalSfixed32());
297 assertEquals(1.5
f,
message.getOptionalFloat(), 0.0f);
298 assertEquals(1.25,
message.getOptionalDouble(), 0.0);
299 assertEquals(
true,
message.getOptionalBool());
304 TestAllTypes.Builder builder = TestAllTypes.newBuilder();
307 +
" \"repeatedInt32\": [1.000, 1e5, \"1.000\", \"1e5\"],\n"
308 +
" \"repeatedUint32\": [1.000, 1e5, \"1.000\", \"1e5\"],\n"
309 +
" \"repeatedInt64\": [1.000, 1e5, \"1.000\", \"1e5\"],\n"
310 +
" \"repeatedUint64\": [1.000, 1e5, \"1.000\", \"1e5\"]\n"
313 int[] expectedValues =
new int[] {1, 100000, 1, 100000};
314 assertEquals(4, builder.getRepeatedInt32Count());
315 assertEquals(4, builder.getRepeatedUint32Count());
316 assertEquals(4, builder.getRepeatedInt64Count());
317 assertEquals(4, builder.getRepeatedUint64Count());
318 for (
int i = 0;
i < 4; ++
i) {
319 assertEquals(expectedValues[
i], builder.getRepeatedInt32(
i));
320 assertEquals(expectedValues[
i], builder.getRepeatedUint32(
i));
321 assertEquals(expectedValues[
i], builder.getRepeatedInt64(
i));
322 assertEquals(expectedValues[
i], builder.getRepeatedUint64(
i));
333 TestAllTypes.Builder builder = TestAllTypes.newBuilder();
337 fail(
"Exception is expected.");
338 }
catch (IOException e) {
344 fail(
"Exception is expected.");
345 }
catch (IOException e) {
351 TestAllTypes.Builder builder = TestAllTypes.newBuilder();
359 assertAccepts(
"optionalInt32", String.valueOf(Integer.MAX_VALUE));
360 assertAccepts(
"optionalInt32", String.valueOf(Integer.MIN_VALUE));
361 assertRejects(
"optionalInt32", String.valueOf(Integer.MAX_VALUE + 1L));
362 assertRejects(
"optionalInt32", String.valueOf(Integer.MIN_VALUE - 1L));
364 assertAccepts(
"optionalUint32", String.valueOf(Integer.MAX_VALUE + 1L));
368 BigInteger one =
new BigInteger(
"1");
369 BigInteger maxLong =
new BigInteger(String.valueOf(Long.MAX_VALUE));
370 BigInteger minLong =
new BigInteger(String.valueOf(Long.MIN_VALUE));
374 assertRejects(
"optionalInt64", minLong.subtract(one).toString());
376 assertAccepts(
"optionalUint64", maxLong.add(one).toString());
377 assertRejects(
"optionalUint64",
"1234567890123456789012345");
389 BigDecimal moreThanOne =
new BigDecimal(
"1.000001");
390 BigDecimal maxDouble =
new BigDecimal(
Double.MAX_VALUE);
391 BigDecimal minDouble =
new BigDecimal(-
Double.MAX_VALUE);
394 assertRejects(
"optionalDouble", maxDouble.multiply(moreThanOne).toString());
395 assertRejects(
"optionalDouble", minDouble.multiply(moreThanOne).toString());
399 TestAllTypes.Builder builder = TestAllTypes.newBuilder();
402 +
" \"optionalInt32\": null,\n"
403 +
" \"optionalInt64\": null,\n"
404 +
" \"optionalUint32\": null,\n"
405 +
" \"optionalUint64\": null,\n"
406 +
" \"optionalSint32\": null,\n"
407 +
" \"optionalSint64\": null,\n"
408 +
" \"optionalFixed32\": null,\n"
409 +
" \"optionalFixed64\": null,\n"
410 +
" \"optionalSfixed32\": null,\n"
411 +
" \"optionalSfixed64\": null,\n"
412 +
" \"optionalFloat\": null,\n"
413 +
" \"optionalDouble\": null,\n"
414 +
" \"optionalBool\": null,\n"
415 +
" \"optionalString\": null,\n"
416 +
" \"optionalBytes\": null,\n"
417 +
" \"optionalNestedMessage\": null,\n"
418 +
" \"optionalNestedEnum\": null,\n"
419 +
" \"repeatedInt32\": null,\n"
420 +
" \"repeatedInt64\": null,\n"
421 +
" \"repeatedUint32\": null,\n"
422 +
" \"repeatedUint64\": null,\n"
423 +
" \"repeatedSint32\": null,\n"
424 +
" \"repeatedSint64\": null,\n"
425 +
" \"repeatedFixed32\": null,\n"
426 +
" \"repeatedFixed64\": null,\n"
427 +
" \"repeatedSfixed32\": null,\n"
428 +
" \"repeatedSfixed64\": null,\n"
429 +
" \"repeatedFloat\": null,\n"
430 +
" \"repeatedDouble\": null,\n"
431 +
" \"repeatedBool\": null,\n"
432 +
" \"repeatedString\": null,\n"
433 +
" \"repeatedBytes\": null,\n"
434 +
" \"repeatedNestedMessage\": null,\n"
435 +
" \"repeatedNestedEnum\": null\n"
438 TestAllTypes
message = builder.build();
439 assertEquals(TestAllTypes.getDefaultInstance(),
message);
443 builder = TestAllTypes.newBuilder();
444 mergeFromJson(
"{\n" +
" \"repeatedInt32\": [null, null],\n" +
"}", builder);
451 builder = TestAllTypes.newBuilder();
452 mergeFromJson(
"{\n" +
" \"repeatedNestedMessage\": [null, null],\n" +
"}", builder);
460 TestOneof.Builder builder = TestOneof.newBuilder();
461 mergeFromJson(
"{\n" +
" \"oneofNullValue\": null \n" +
"}", builder);
462 TestOneof
message = builder.build();
463 assertEquals(TestOneof.OneofFieldCase.ONEOF_NULL_VALUE,
message.getOneofFieldCase());
468 TestOneof.Builder builder = TestOneof.newBuilder();
469 mergeFromJson(
"{\"oneofNestedMessage\": null, \"oneofInt32\": 1}", builder);
470 TestOneof
message = builder.build();
471 assertEquals(1,
message.getOneofInt32());
475 TestOneof.Builder builder = TestOneof.newBuilder();
476 mergeFromJson(
"{\"oneofInt32\": 1, \"oneofNestedMessage\": null}", builder);
477 TestOneof
message = builder.build();
478 assertEquals(1,
message.getOneofInt32());
489 TestAllTypes.Builder builder = TestAllTypes.newBuilder();
492 +
" \"optionalNestedMessage\": {},\n"
493 +
" \"optional_nested_message\": {}\n"
503 TestAllTypes.Builder builder = TestAllTypes.newBuilder();
506 +
" \"repeatedInt32\": [1, 2],\n"
507 +
" \"repeated_int32\": [5, 6]\n"
517 TestOneof.Builder builder = TestOneof.newBuilder();
518 mergeFromJson(
"{\n" +
" \"oneofInt32\": 1,\n" +
" \"oneof_int32\": 2\n" +
"}", builder);
526 TestOneof.Builder builder = TestOneof.newBuilder();
528 "{\n" +
" \"oneofInt32\": 1,\n" +
" \"oneofNullValue\": null\n" +
"}", builder);
536 TestMap.Builder builder = TestMap.newBuilder();
537 builder.putInt32ToInt32Map(1, 10);
538 builder.putInt64ToInt32Map(1234567890123456789L, 10);
539 builder.putUint32ToInt32Map(2, 20);
540 builder.putUint64ToInt32Map(2234567890123456789L, 20);
541 builder.putSint32ToInt32Map(3, 30);
542 builder.putSint64ToInt32Map(3234567890123456789L, 30);
543 builder.putFixed32ToInt32Map(4, 40);
544 builder.putFixed64ToInt32Map(4234567890123456789L, 40);
545 builder.putSfixed32ToInt32Map(5, 50);
546 builder.putSfixed64ToInt32Map(5234567890123456789L, 50);
547 builder.putBoolToInt32Map(
false, 6);
548 builder.putStringToInt32Map(
"Hello", 10);
550 builder.putInt32ToInt64Map(1, 1234567890123456789L);
551 builder.putInt32ToUint32Map(2, 20);
552 builder.putInt32ToUint64Map(2, 2234567890123456789L);
553 builder.putInt32ToSint32Map(3, 30);
554 builder.putInt32ToSint64Map(3, 3234567890123456789L);
555 builder.putInt32ToFixed32Map(4, 40);
556 builder.putInt32ToFixed64Map(4, 4234567890123456789L);
557 builder.putInt32ToSfixed32Map(5, 50);
558 builder.putInt32ToSfixed64Map(5, 5234567890123456789L);
559 builder.putInt32ToFloatMap(6, 1.5
f);
560 builder.putInt32ToDoubleMap(6, 1.25);
561 builder.putInt32ToBoolMap(7,
false);
562 builder.putInt32ToStringMap(7,
"World");
563 builder.putInt32ToBytesMap(8,
ByteString.copyFrom(
new byte[] {1, 2, 3}));
564 builder.putInt32ToMessageMap(8, NestedMessage.newBuilder().setValue(1234).build());
565 builder.putInt32ToEnumMap(9, NestedEnum.BAR);
566 TestMap
message = builder.build();
570 +
" \"int32ToInt32Map\": {\n"
573 +
" \"int64ToInt32Map\": {\n"
574 +
" \"1234567890123456789\": 10\n"
576 +
" \"uint32ToInt32Map\": {\n"
579 +
" \"uint64ToInt32Map\": {\n"
580 +
" \"2234567890123456789\": 20\n"
582 +
" \"sint32ToInt32Map\": {\n"
585 +
" \"sint64ToInt32Map\": {\n"
586 +
" \"3234567890123456789\": 30\n"
588 +
" \"fixed32ToInt32Map\": {\n"
591 +
" \"fixed64ToInt32Map\": {\n"
592 +
" \"4234567890123456789\": 40\n"
594 +
" \"sfixed32ToInt32Map\": {\n"
597 +
" \"sfixed64ToInt32Map\": {\n"
598 +
" \"5234567890123456789\": 50\n"
600 +
" \"boolToInt32Map\": {\n"
603 +
" \"stringToInt32Map\": {\n"
606 +
" \"int32ToInt64Map\": {\n"
607 +
" \"1\": \"1234567890123456789\"\n"
609 +
" \"int32ToUint32Map\": {\n"
612 +
" \"int32ToUint64Map\": {\n"
613 +
" \"2\": \"2234567890123456789\"\n"
615 +
" \"int32ToSint32Map\": {\n"
618 +
" \"int32ToSint64Map\": {\n"
619 +
" \"3\": \"3234567890123456789\"\n"
621 +
" \"int32ToFixed32Map\": {\n"
624 +
" \"int32ToFixed64Map\": {\n"
625 +
" \"4\": \"4234567890123456789\"\n"
627 +
" \"int32ToSfixed32Map\": {\n"
630 +
" \"int32ToSfixed64Map\": {\n"
631 +
" \"5\": \"5234567890123456789\"\n"
633 +
" \"int32ToFloatMap\": {\n"
636 +
" \"int32ToDoubleMap\": {\n"
639 +
" \"int32ToBoolMap\": {\n"
642 +
" \"int32ToStringMap\": {\n"
643 +
" \"7\": \"World\"\n"
645 +
" \"int32ToBytesMap\": {\n"
646 +
" \"8\": \"AQID\"\n"
648 +
" \"int32ToMessageMap\": {\n"
650 +
" \"value\": 1234\n"
653 +
" \"int32ToEnumMap\": {\n"
654 +
" \"9\": \"BAR\"\n"
661 builder = TestMap.newBuilder();
662 builder.putInt32ToInt32Map(1, 2);
663 builder.putInt32ToInt32Map(3, 4);
667 "{\n" +
" \"int32ToInt32Map\": {\n" +
" \"1\": 2,\n" +
" \"3\": 4\n" +
" }\n" +
"}",
674 TestMap.Builder builder = TestMap.newBuilder();
677 +
" \"int32ToInt32Map\": {null: 1},\n"
678 +
" \"int32ToMessageMap\": {null: 2}\n"
687 TestMap.Builder builder = TestMap.newBuilder();
690 +
" \"int32ToInt32Map\": {\"1\": null},\n"
691 +
" \"int32ToMessageMap\": {\"2\": null}\n"
702 TestMap.Builder builder = TestMap.newBuilder();
704 "{\n" +
" \"int32ToEnumMap\": {\"1\": null}\n" +
"}", builder);
705 TestMap
map = builder.build();
706 assertEquals(0,
map.getInt32ToEnumMapMap().size());
710 TestMap.Builder builder = TestMap.newBuilder();
712 "{\n" +
" int32ToInt32Map: {1: 2},\n" +
" stringToInt32Map: {hello: 3}\n" +
"}", builder);
713 TestMap
message = builder.build();
714 assertEquals(2,
message.getInt32ToInt32Map().get(1).intValue());
715 assertEquals(3,
message.getStringToInt32Map().get(
"hello").intValue());
719 TestWrappers.Builder builder = TestWrappers.newBuilder();
720 builder.getBoolValueBuilder().setValue(
false);
721 builder.getInt32ValueBuilder().setValue(0);
722 builder.getInt64ValueBuilder().setValue(0);
723 builder.getUint32ValueBuilder().setValue(0);
724 builder.getUint64ValueBuilder().setValue(0);
725 builder.getFloatValueBuilder().setValue(0.0
f);
726 builder.getDoubleValueBuilder().setValue(0.0);
727 builder.getStringValueBuilder().setValue(
"");
729 TestWrappers
message = builder.build();
733 +
" \"int32Value\": 0,\n"
734 +
" \"uint32Value\": 0,\n"
735 +
" \"int64Value\": \"0\",\n"
736 +
" \"uint64Value\": \"0\",\n"
737 +
" \"floatValue\": 0.0,\n"
738 +
" \"doubleValue\": 0.0,\n"
739 +
" \"boolValue\": false,\n"
740 +
" \"stringValue\": \"\",\n"
741 +
" \"bytesValue\": \"\"\n"
746 builder = TestWrappers.newBuilder();
747 builder.getBoolValueBuilder().setValue(
true);
748 builder.getInt32ValueBuilder().setValue(1);
749 builder.getInt64ValueBuilder().setValue(2);
750 builder.getUint32ValueBuilder().setValue(3);
751 builder.getUint64ValueBuilder().setValue(4);
752 builder.getFloatValueBuilder().setValue(5.0
f);
753 builder.getDoubleValueBuilder().setValue(6.0);
754 builder.getStringValueBuilder().setValue(
"7");
755 builder.getBytesValueBuilder().setValue(
ByteString.copyFrom(
new byte[] {8}));
760 +
" \"int32Value\": 1,\n"
761 +
" \"uint32Value\": 3,\n"
762 +
" \"int64Value\": \"2\",\n"
763 +
" \"uint64Value\": \"4\",\n"
764 +
" \"floatValue\": 5.0,\n"
765 +
" \"doubleValue\": 6.0,\n"
766 +
" \"boolValue\": true,\n"
767 +
" \"stringValue\": \"7\",\n"
768 +
" \"bytesValue\": \"CA==\"\n"
776 TestTimestamp.newBuilder()
787 TestDuration.newBuilder().setDurationValue(
Durations.
parse(
"12345s")).build();
795 TestFieldMask.newBuilder()
806 TestStruct.Builder builder = TestStruct.newBuilder();
807 Struct.Builder structBuilder = builder.getStructValueBuilder();
808 structBuilder.putFields(
"null_value",
Value.newBuilder().setNullValueValue(0).build());
809 structBuilder.putFields(
"number_value",
Value.newBuilder().setNumberValue(1.25).build());
810 structBuilder.putFields(
"string_value",
Value.newBuilder().setStringValue(
"hello").build());
812 subStructBuilder.putFields(
"number_value",
Value.newBuilder().setNumberValue(1234).build());
813 structBuilder.putFields(
814 "struct_value",
Value.newBuilder().setStructValue(subStructBuilder.build()).build());
816 listBuilder.addValues(
Value.newBuilder().setNumberValue(1.125).build());
817 listBuilder.addValues(
Value.newBuilder().setNullValueValue(0).build());
818 structBuilder.putFields(
819 "list_value",
Value.newBuilder().setListValue(listBuilder.build()).build());
820 TestStruct
message = builder.build();
824 +
" \"structValue\": {\n"
825 +
" \"null_value\": null,\n"
826 +
" \"number_value\": 1.25,\n"
827 +
" \"string_value\": \"hello\",\n"
828 +
" \"struct_value\": {\n"
829 +
" \"number_value\": 1234.0\n"
831 +
" \"list_value\": [1.125, null]\n"
837 builder = TestStruct.newBuilder();
838 builder.setValue(
Value.newBuilder().setNullValueValue(0).build());
843 builder = TestStruct.newBuilder();
844 listBuilder = builder.getListValueBuilder();
845 listBuilder.addValues(
Value.newBuilder().setNumberValue(31831.125).build());
846 listBuilder.addValues(
Value.newBuilder().setNullValueValue(0).build());
854 TestAllTypes content = TestAllTypes.newBuilder().setOptionalInt32(1234).build();
855 TestAny
message = TestAny.newBuilder().setAnyValue(
Any.pack(content)).build();
860 fail(
"Exception is expected.");
861 }
catch (IOException e) {
871 +
" \"anyValue\": {\n"
872 +
" \"@type\": \"type.googleapis.com/json_test.TestAllTypes\",\n"
873 +
" \"optionalInt32\": 1234\n"
879 TestAny messageWithDefaultAnyValue =
880 TestAny.newBuilder().setAnyValue(
Any.getDefaultInstance()).build();
883 +
" \"anyValue\": {}\n"
885 printer.print(messageWithDefaultAnyValue));
891 Any anyMessage =
Any.pack(
Any.pack(content));
894 +
" \"@type\": \"type.googleapis.com/google.protobuf.Any\",\n"
896 +
" \"@type\": \"type.googleapis.com/json_test.TestAllTypes\",\n"
897 +
" \"optionalInt32\": 1234\n"
900 printer.print(anyMessage));
904 anyMessage =
Any.pack(
Int32Value.newBuilder().setValue(12345).build());
907 +
" \"@type\": \"type.googleapis.com/google.protobuf.Int32Value\",\n"
908 +
" \"value\": 12345\n"
910 printer.print(anyMessage));
912 anyMessage =
Any.pack(
UInt32Value.newBuilder().setValue(12345).build());
915 +
" \"@type\": \"type.googleapis.com/google.protobuf.UInt32Value\",\n"
916 +
" \"value\": 12345\n"
918 printer.print(anyMessage));
920 anyMessage =
Any.pack(
Int64Value.newBuilder().setValue(12345).build());
923 +
" \"@type\": \"type.googleapis.com/google.protobuf.Int64Value\",\n"
924 +
" \"value\": \"12345\"\n"
926 printer.print(anyMessage));
928 anyMessage =
Any.pack(
UInt64Value.newBuilder().setValue(12345).build());
931 +
" \"@type\": \"type.googleapis.com/google.protobuf.UInt64Value\",\n"
932 +
" \"value\": \"12345\"\n"
934 printer.print(anyMessage));
936 anyMessage =
Any.pack(
FloatValue.newBuilder().setValue(12345).build());
939 +
" \"@type\": \"type.googleapis.com/google.protobuf.FloatValue\",\n"
940 +
" \"value\": 12345.0\n"
942 printer.print(anyMessage));
944 anyMessage =
Any.pack(
DoubleValue.newBuilder().setValue(12345).build());
947 +
" \"@type\": \"type.googleapis.com/google.protobuf.DoubleValue\",\n"
948 +
" \"value\": 12345.0\n"
950 printer.print(anyMessage));
952 anyMessage =
Any.pack(
BoolValue.newBuilder().setValue(
true).build());
955 +
" \"@type\": \"type.googleapis.com/google.protobuf.BoolValue\",\n"
956 +
" \"value\": true\n"
958 printer.print(anyMessage));
960 anyMessage =
Any.pack(
StringValue.newBuilder().setValue(
"Hello").build());
963 +
" \"@type\": \"type.googleapis.com/google.protobuf.StringValue\",\n"
964 +
" \"value\": \"Hello\"\n"
966 printer.print(anyMessage));
972 +
" \"@type\": \"type.googleapis.com/google.protobuf.BytesValue\",\n"
973 +
" \"value\": \"AQI=\"\n"
975 printer.print(anyMessage));
982 +
" \"@type\": \"type.googleapis.com/google.protobuf.Timestamp\",\n"
983 +
" \"value\": \"1969-12-31T23:59:59Z\"\n"
985 printer.print(anyMessage));
992 +
" \"@type\": \"type.googleapis.com/google.protobuf.Duration\",\n"
993 +
" \"value\": \"12345.100s\"\n"
995 printer.print(anyMessage));
1002 +
" \"@type\": \"type.googleapis.com/google.protobuf.FieldMask\",\n"
1003 +
" \"value\": \"foo.bar,baz\"\n"
1005 printer.print(anyMessage));
1010 structBuilder.putFields(
"number",
Value.newBuilder().setNumberValue(1.125).build());
1011 anyMessage =
Any.pack(structBuilder.build());
1014 +
" \"@type\": \"type.googleapis.com/google.protobuf.Struct\",\n"
1016 +
" \"number\": 1.125\n"
1019 printer.print(anyMessage));
1023 Value.Builder valueBuilder =
Value.newBuilder();
1024 valueBuilder.setNumberValue(1);
1025 anyMessage =
Any.pack(valueBuilder.build());
1028 +
" \"@type\": \"type.googleapis.com/google.protobuf.Value\",\n"
1029 +
" \"value\": 1.0\n"
1031 printer.print(anyMessage));
1035 anyMessage =
Any.pack(
Value.newBuilder().setNullValue(
NullValue.NULL_VALUE).build());
1038 +
" \"@type\": \"type.googleapis.com/google.protobuf.Value\",\n"
1039 +
" \"value\": null\n"
1041 printer.print(anyMessage));
1050 TestAny.Builder testAny = TestAny.newBuilder();
1051 testAny.putAnyMap(
"int32_wrapper",
Any.pack(
Int32Value.newBuilder().setValue(123).build()));
1052 testAny.putAnyMap(
"int64_wrapper",
Any.pack(
Int64Value.newBuilder().setValue(456).build()));
1056 Value numberValue =
Value.newBuilder().setNumberValue(1.125).build();
1057 Struct.Builder
struct = Struct.newBuilder();
1058 struct.putFields(
"number", numberValue);
1059 testAny.putAnyMap(
"struct",
Any.pack(
struct.build()));
1064 testAny.putAnyMap(
"number_value",
Any.pack(numberValue));
1065 testAny.putAnyMap(
"any_value_number",
Any.pack(
Any.pack(numberValue)));
1066 testAny.putAnyMap(
"any_value_default",
Any.pack(
Any.getDefaultInstance()));
1067 testAny.putAnyMap(
"default",
Any.getDefaultInstance());
1071 +
" \"anyMap\": {\n"
1072 +
" \"int32_wrapper\": {\n"
1073 +
" \"@type\": \"type.googleapis.com/google.protobuf.Int32Value\",\n"
1074 +
" \"value\": 123\n"
1076 +
" \"int64_wrapper\": {\n"
1077 +
" \"@type\": \"type.googleapis.com/google.protobuf.Int64Value\",\n"
1078 +
" \"value\": \"456\"\n"
1080 +
" \"timestamp\": {\n"
1081 +
" \"@type\": \"type.googleapis.com/google.protobuf.Timestamp\",\n"
1082 +
" \"value\": \"1969-12-31T23:59:59Z\"\n"
1084 +
" \"duration\": {\n"
1085 +
" \"@type\": \"type.googleapis.com/google.protobuf.Duration\",\n"
1086 +
" \"value\": \"12345.100s\"\n"
1088 +
" \"field_mask\": {\n"
1089 +
" \"@type\": \"type.googleapis.com/google.protobuf.FieldMask\",\n"
1090 +
" \"value\": \"foo.bar,baz\"\n"
1092 +
" \"struct\": {\n"
1093 +
" \"@type\": \"type.googleapis.com/google.protobuf.Struct\",\n"
1095 +
" \"number\": 1.125\n"
1098 +
" \"list_value\": {\n"
1099 +
" \"@type\": \"type.googleapis.com/google.protobuf.ListValue\",\n"
1100 +
" \"value\": [1.125, null]\n"
1102 +
" \"number_value\": {\n"
1103 +
" \"@type\": \"type.googleapis.com/google.protobuf.Value\",\n"
1104 +
" \"value\": 1.125\n"
1106 +
" \"any_value_number\": {\n"
1107 +
" \"@type\": \"type.googleapis.com/google.protobuf.Any\",\n"
1109 +
" \"@type\": \"type.googleapis.com/google.protobuf.Value\",\n"
1110 +
" \"value\": 1.125\n"
1113 +
" \"any_value_default\": {\n"
1114 +
" \"@type\": \"type.googleapis.com/google.protobuf.Any\",\n"
1115 +
" \"value\": {}\n"
1117 +
" \"default\": {}\n"
1120 printer.print(testAny.build()));
1126 Any.Builder builder =
Any.newBuilder();
1127 mergeFromJson(
"{\n" +
" \"optionalInt32\": 1234\n" +
"}", builder);
1128 fail(
"Exception is expected.");
1129 }
catch (IOException e) {
1136 Any.Builder builder =
Any.newBuilder();
1139 +
" \"@type\": \"type.googleapis.com/json_test.TestAllTypes\",\n"
1140 +
" \"optionalInt32\": 12345\n"
1143 fail(
"Exception is expected.");
1144 }
catch (IOException e) {
1151 TestAllTypes.Builder builder = TestAllTypes.newBuilder();
1152 mergeFromJson(
"{\n" +
" \"optionalInt32\": 12345,\n" +
"}", builder);
1153 fail(
"Exception is expected.");
1154 }
catch (IOException e) {
1185 TestAllTypes.Builder builder = TestAllTypes.newBuilder();
1186 mergeFromJson(
"{\n" +
" \"optionalNestedEnum\": \"XXX\"\n" +
"}", builder);
1187 fail(
"Exception is expected.");
1195 TestAllTypes.Builder builder = TestAllTypes.newBuilder();
1196 String json =
"{\n" +
" \"unknownField\": \"XXX\"\n" +
"}";
1198 fail(
"Exception is expected.");
1205 TestAllTypes.Builder builder = TestAllTypes.newBuilder();
1206 String json =
"{\n" +
" \"unknownField\": \"XXX\"\n" +
"}";
1211 TestAllTypes.Builder builder = TestAllTypes.newBuilder();
1212 String json =
"{\n" +
" \"optionalNestedEnum\": \"XXX\"\n" +
"}";
1214 assertEquals(0, builder.getOptionalNestedEnumValue());
1218 TestAllTypes.Builder builder = TestAllTypes.newBuilder();
1219 String json =
"{\n" +
" \"optionalAliasedEnum\": \"QUX\"\n" +
"}";
1221 assertEquals(AliasedEnum.ALIAS_BAZ, builder.getOptionalAliasedEnum());
1223 builder = TestAllTypes.newBuilder();
1224 json =
"{\n" +
" \"optionalAliasedEnum\": \"qux\"\n" +
"}";
1226 assertEquals(AliasedEnum.ALIAS_BAZ, builder.getOptionalAliasedEnum());
1228 builder = TestAllTypes.newBuilder();
1229 json =
"{\n" +
" \"optionalAliasedEnum\": \"bAz\"\n" +
"}";
1231 assertEquals(AliasedEnum.ALIAS_BAZ, builder.getOptionalAliasedEnum());
1235 TestMap.Builder builder = TestMap.newBuilder();
1238 .merge(
"{\n" +
" \"int32ToEnumMap\": {1: XXX, 2: FOO}" +
"}", builder);
1240 assertEquals(NestedEnum.FOO, builder.getInt32ToEnumMapMap().get(2));
1241 assertEquals(1, builder.getInt32ToEnumMapMap().size());
1245 TestAllTypes.Builder builder = TestAllTypes.newBuilder();
1248 .merge(
"{\n" +
" \"repeatedNestedEnum\": [XXX, FOO, BAR, BAZ]" +
"}", builder);
1250 assertEquals(NestedEnum.FOO, builder.getRepeatedNestedEnum(0));
1251 assertEquals(NestedEnum.BAR, builder.getRepeatedNestedEnum(1));
1252 assertEquals(NestedEnum.BAZ, builder.getRepeatedNestedEnum(2));
1253 assertEquals(3, builder.getRepeatedNestedEnumList().size());
1257 TestAllTypes.Builder actualBuilder = TestAllTypes.newBuilder();
1258 mergeFromJson(
"{\n" +
" \"optionalNestedEnum\": 2\n" +
"}", actualBuilder);
1260 TestAllTypes expected = TestAllTypes.newBuilder().setOptionalNestedEnum(NestedEnum.BAZ).build();
1261 assertEquals(expected, actualBuilder.build());
1265 TestCustomJsonName
message = TestCustomJsonName.newBuilder().setValue(12345).build();
1272 TestAllTypes
message = TestAllTypes.newBuilder().setOptionalString(
"</script>").build();
1273 assertEquals(
"{\n \"optionalString\": \"\\u003c/script\\u003e\"\n}",
toJsonString(
message));
1275 TestAllTypes.Builder builder = TestAllTypes.newBuilder();
1277 assertEquals(
message.getOptionalString(), builder.getOptionalString());
1281 TestAllTypes
message = TestAllTypes.getDefaultInstance();
1285 +
" \"optionalInt32\": 0,\n"
1286 +
" \"optionalInt64\": \"0\",\n"
1287 +
" \"optionalUint32\": 0,\n"
1288 +
" \"optionalUint64\": \"0\",\n"
1289 +
" \"optionalSint32\": 0,\n"
1290 +
" \"optionalSint64\": \"0\",\n"
1291 +
" \"optionalFixed32\": 0,\n"
1292 +
" \"optionalFixed64\": \"0\",\n"
1293 +
" \"optionalSfixed32\": 0,\n"
1294 +
" \"optionalSfixed64\": \"0\",\n"
1295 +
" \"optionalFloat\": 0.0,\n"
1296 +
" \"optionalDouble\": 0.0,\n"
1297 +
" \"optionalBool\": false,\n"
1298 +
" \"optionalString\": \"\",\n"
1299 +
" \"optionalBytes\": \"\",\n"
1300 +
" \"optionalNestedEnum\": \"FOO\",\n"
1301 +
" \"repeatedInt32\": [],\n"
1302 +
" \"repeatedInt64\": [],\n"
1303 +
" \"repeatedUint32\": [],\n"
1304 +
" \"repeatedUint64\": [],\n"
1305 +
" \"repeatedSint32\": [],\n"
1306 +
" \"repeatedSint64\": [],\n"
1307 +
" \"repeatedFixed32\": [],\n"
1308 +
" \"repeatedFixed64\": [],\n"
1309 +
" \"repeatedSfixed32\": [],\n"
1310 +
" \"repeatedSfixed64\": [],\n"
1311 +
" \"repeatedFloat\": [],\n"
1312 +
" \"repeatedDouble\": [],\n"
1313 +
" \"repeatedBool\": [],\n"
1314 +
" \"repeatedString\": [],\n"
1315 +
" \"repeatedBytes\": [],\n"
1316 +
" \"repeatedNestedMessage\": [],\n"
1317 +
" \"repeatedNestedEnum\": [],\n"
1318 +
" \"optionalAliasedEnum\": \"ALIAS_FOO\"\n"
1322 Set<FieldDescriptor> fixedFields =
new HashSet<FieldDescriptor>();
1323 for (
FieldDescriptor fieldDesc : TestAllTypes.getDescriptor().getFields()) {
1324 if (fieldDesc.getName().contains(
"_fixed")) {
1325 fixedFields.add(fieldDesc);
1331 +
" \"optionalFixed32\": 0,\n"
1332 +
" \"optionalFixed64\": \"0\",\n"
1333 +
" \"repeatedFixed32\": [],\n"
1334 +
" \"repeatedFixed64\": []\n"
1338 TestAllTypes messageNonDefaults =
1339 message.toBuilder().setOptionalInt64(1234).setOptionalFixed32(3232).build();
1342 +
" \"optionalInt64\": \"1234\",\n"
1343 +
" \"optionalFixed32\": 3232,\n"
1344 +
" \"optionalFixed64\": \"0\",\n"
1345 +
" \"repeatedFixed32\": [],\n"
1346 +
" \"repeatedFixed64\": []\n"
1352 fail(
"IllegalStateException is expected.");
1353 }
catch (IllegalStateException e) {
1356 "Exception message should mention includingDefaultValueFields.",
1357 e.getMessage().contains(
"includingDefaultValueFields"));
1362 fail(
"IllegalStateException is expected.");
1363 }
catch (IllegalStateException e) {
1366 "Exception message should mention includingDefaultValueFields.",
1367 e.getMessage().contains(
"includingDefaultValueFields"));
1372 fail(
"IllegalStateException is expected.");
1373 }
catch (IllegalStateException e) {
1376 "Exception message should mention includingDefaultValueFields.",
1377 e.getMessage().contains(
"includingDefaultValueFields"));
1383 .includingDefaultValueFields(fixedFields);
1384 fail(
"IllegalStateException is expected.");
1385 }
catch (IllegalStateException e) {
1388 "Exception message should mention includingDefaultValueFields.",
1389 e.getMessage().contains(
"includingDefaultValueFields"));
1392 Set<FieldDescriptor> intFields =
new HashSet<FieldDescriptor>();
1393 for (
FieldDescriptor fieldDesc : TestAllTypes.getDescriptor().getFields()) {
1394 if (fieldDesc.getName().contains(
"_int")) {
1395 intFields.add(fieldDesc);
1402 .includingDefaultValueFields(fixedFields);
1403 fail(
"IllegalStateException is expected.");
1404 }
catch (IllegalStateException e) {
1407 "Exception message should mention includingDefaultValueFields.",
1408 e.getMessage().contains(
"includingDefaultValueFields"));
1413 fail(
"IllegalArgumentException is expected.");
1414 }
catch (IllegalArgumentException e) {
1417 "Exception message should mention includingDefaultValueFields.",
1418 e.getMessage().contains(
"includingDefaultValueFields"));
1423 fail(
"IllegalArgumentException is expected.");
1424 }
catch (IllegalArgumentException e) {
1427 "Exception message should mention includingDefaultValueFields.",
1428 e.getMessage().contains(
"includingDefaultValueFields"));
1431 TestMap mapMessage = TestMap.getDefaultInstance();
1435 +
" \"int32ToInt32Map\": {\n"
1437 +
" \"int64ToInt32Map\": {\n"
1439 +
" \"uint32ToInt32Map\": {\n"
1441 +
" \"uint64ToInt32Map\": {\n"
1443 +
" \"sint32ToInt32Map\": {\n"
1445 +
" \"sint64ToInt32Map\": {\n"
1447 +
" \"fixed32ToInt32Map\": {\n"
1449 +
" \"fixed64ToInt32Map\": {\n"
1451 +
" \"sfixed32ToInt32Map\": {\n"
1453 +
" \"sfixed64ToInt32Map\": {\n"
1455 +
" \"boolToInt32Map\": {\n"
1457 +
" \"stringToInt32Map\": {\n"
1459 +
" \"int32ToInt64Map\": {\n"
1461 +
" \"int32ToUint32Map\": {\n"
1463 +
" \"int32ToUint64Map\": {\n"
1465 +
" \"int32ToSint32Map\": {\n"
1467 +
" \"int32ToSint64Map\": {\n"
1469 +
" \"int32ToFixed32Map\": {\n"
1471 +
" \"int32ToFixed64Map\": {\n"
1473 +
" \"int32ToSfixed32Map\": {\n"
1475 +
" \"int32ToSfixed64Map\": {\n"
1477 +
" \"int32ToFloatMap\": {\n"
1479 +
" \"int32ToDoubleMap\": {\n"
1481 +
" \"int32ToBoolMap\": {\n"
1483 +
" \"int32ToStringMap\": {\n"
1485 +
" \"int32ToBytesMap\": {\n"
1487 +
" \"int32ToMessageMap\": {\n"
1489 +
" \"int32ToEnumMap\": {\n"
1494 TestOneof oneofMessage = TestOneof.getDefaultInstance();
1498 oneofMessage = TestOneof.newBuilder().setOneofInt32(42).build();
1501 "{\n \"oneofInt32\": 42\n}",
1504 TestOneof.Builder oneofBuilder = TestOneof.newBuilder();
1505 mergeFromJson(
"{\n" +
" \"oneofNullValue\": null \n" +
"}", oneofBuilder);
1506 oneofMessage = oneofBuilder.build();
1509 "{\n \"oneofNullValue\": null\n}",
1514 TestAllTypes
message = TestAllTypes.newBuilder().setOptionalInt32(12345).build();
1517 "{\n" +
" \"optional_int32\": 12345\n" +
"}",
1521 TestCustomJsonName messageWithCustomJsonName =
1522 TestCustomJsonName.newBuilder().setValue(12345).build();
1524 "{\n" +
" \"value\": 12345\n" +
"}",
1528 TestAllTypes.Builder builder = TestAllTypes.newBuilder();
1530 assertEquals(12345, builder.getOptionalInt32());
1533 assertEquals(54321, builder.getOptionalInt32());
1537 TestAllTypes
message = TestAllTypes.newBuilder().setOptionalNestedEnum(NestedEnum.BAR).build();
1539 "{\n" +
" \"optionalNestedEnum\": 1\n" +
"}",
1544 TestAllTypes
message = TestAllTypes.newBuilder().setOptionalInt32(12345).build();
1546 "{" +
"\"optionalInt32\":12345" +
"}",
1548 TestAllTypes message1 = TestAllTypes.getDefaultInstance();
1550 TestAllTypes.Builder builder = TestAllTypes.newBuilder();
1552 TestAllTypes message2 = builder.build();
1555 +
"\"optionalInt32\":1234,"
1556 +
"\"optionalInt64\":\"1234567890123456789\","
1557 +
"\"optionalUint32\":5678,"
1558 +
"\"optionalUint64\":\"2345678901234567890\","
1559 +
"\"optionalSint32\":9012,"
1560 +
"\"optionalSint64\":\"3456789012345678901\","
1561 +
"\"optionalFixed32\":3456,"
1562 +
"\"optionalFixed64\":\"4567890123456789012\","
1563 +
"\"optionalSfixed32\":7890,"
1564 +
"\"optionalSfixed64\":\"5678901234567890123\","
1565 +
"\"optionalFloat\":1.5,"
1566 +
"\"optionalDouble\":1.25,"
1567 +
"\"optionalBool\":true,"
1568 +
"\"optionalString\":\"Hello world!\","
1569 +
"\"optionalBytes\":\"AAEC\","
1570 +
"\"optionalNestedMessage\":{"
1573 +
"\"optionalNestedEnum\":\"BAR\","
1574 +
"\"repeatedInt32\":[1234,234],"
1575 +
"\"repeatedInt64\":[\"1234567890123456789\",\"234567890123456789\"],"
1576 +
"\"repeatedUint32\":[5678,678],"
1577 +
"\"repeatedUint64\":[\"2345678901234567890\",\"345678901234567890\"],"
1578 +
"\"repeatedSint32\":[9012,10],"
1579 +
"\"repeatedSint64\":[\"3456789012345678901\",\"456789012345678901\"],"
1580 +
"\"repeatedFixed32\":[3456,456],"
1581 +
"\"repeatedFixed64\":[\"4567890123456789012\",\"567890123456789012\"],"
1582 +
"\"repeatedSfixed32\":[7890,890],"
1583 +
"\"repeatedSfixed64\":[\"5678901234567890123\",\"678901234567890123\"],"
1584 +
"\"repeatedFloat\":[1.5,11.5],"
1585 +
"\"repeatedDouble\":[1.25,11.25],"
1586 +
"\"repeatedBool\":[true,true],"
1587 +
"\"repeatedString\":[\"Hello world!\",\"ello world!\"],"
1588 +
"\"repeatedBytes\":[\"AAEC\",\"AQI=\"],"
1589 +
"\"repeatedNestedMessage\":[{"
1594 +
"\"repeatedNestedEnum\":[\"BAR\",\"BAZ\"]"
1605 Any.Builder builder =
Any.newBuilder();
1608 +
" \"@type\": \"type.googleapis.com/google.protobuf.BoolValue\",\n"
1609 +
" \"value\": false\n"
1612 Any any = builder.build();
1613 assertEquals(0, any.getValue().size());
1619 +
" \"nested\": {\n"
1620 +
" \"nested\": {\n"
1621 +
" \"nested\": {\n"
1622 +
" \"nested\": {\n"
1623 +
" \"value\": 1234\n"
1631 TestRecursive.Builder builder = TestRecursive.newBuilder();
1633 TestRecursive
message = builder.build();
1634 assertEquals(1234,
message.getNested().getNested().getNested().getNested().getValue());
1637 builder = TestRecursive.newBuilder();
1640 fail(
"Exception is expected.");
1648 InputStream throwingInputStream =
1650 public int read()
throws IOException {
1651 throw new IOException(
"12345");
1654 InputStreamReader throwingReader =
new InputStreamReader(throwingInputStream);
1658 TestAllTypes.Builder builder = TestAllTypes.newBuilder();
1660 fail(
"Exception is expected.");
1661 }
catch (IOException e) {
1662 assertEquals(
"12345", e.getMessage());
1665 Reader invalidJsonReader =
new StringReader(
"{ xxx - yyy }");
1669 TestAllTypes.Builder builder = TestAllTypes.newBuilder();
1671 fail(
"Exception is expected.");
1678 TestMap.Builder mapBuilder = TestMap.newBuilder();
1679 mapBuilder.putStringToInt32Map(
"\ud834\udd20", 3);
1680 mapBuilder.putStringToInt32Map(
"foo", 99);
1681 mapBuilder.putStringToInt32Map(
"xxx", 123);
1682 mapBuilder.putStringToInt32Map(
"\u20ac", 1);
1683 mapBuilder.putStringToInt32Map(
"abc", 20);
1684 mapBuilder.putStringToInt32Map(
"19", 19);
1685 mapBuilder.putStringToInt32Map(
"8", 8);
1686 mapBuilder.putStringToInt32Map(
"\ufb00", 2);
1687 mapBuilder.putInt32ToInt32Map(3, 3);
1688 mapBuilder.putInt32ToInt32Map(10, 10);
1689 mapBuilder.putInt32ToInt32Map(5, 5);
1690 mapBuilder.putInt32ToInt32Map(4, 4);
1691 mapBuilder.putInt32ToInt32Map(1, 1);
1692 mapBuilder.putInt32ToInt32Map(2, 2);
1693 mapBuilder.putInt32ToInt32Map(-3, -3);
1694 TestMap mapMessage = mapBuilder.build();
1697 +
" \"int32ToInt32Map\": {\n"
1706 +
" \"stringToInt32Map\": {\n"
1711 +
" \"xxx\": 123,\n"
1712 +
" \"\u20ac\": 1,\n"
1713 +
" \"\ufb00\": 2,\n"
1714 +
" \"\ud834\udd20\": 3\n"
1719 TestMap emptyMap = TestMap.getDefaultInstance();