aboutsummaryrefslogtreecommitdiff
path: root/java/util/src/main/java/com/google/protobuf/util/JsonFormat.java
diff options
context:
space:
mode:
authorFeng Xiao <xfxyjwf@gmail.com>2018-08-08 17:14:42 -0700
committerFeng Xiao <xfxyjwf@gmail.com>2018-08-08 17:14:42 -0700
commita8465b738e5a1f346ece58ea6f82612bcd6659d2 (patch)
treeb755540a5d7d2cc988eabc7ac594e6abd9da29d1 /java/util/src/main/java/com/google/protobuf/util/JsonFormat.java
parent6bbe197e9c1b6fc38cbdc45e3bf83fa7ced792a3 (diff)
parent9bbc4b1fab8262958c172f2d8e87b486c950a051 (diff)
downloadprotobuf-a8465b738e5a1f346ece58ea6f82612bcd6659d2.tar.gz
protobuf-a8465b738e5a1f346ece58ea6f82612bcd6659d2.tar.bz2
protobuf-a8465b738e5a1f346ece58ea6f82612bcd6659d2.zip
Merge master branch.
Diffstat (limited to 'java/util/src/main/java/com/google/protobuf/util/JsonFormat.java')
-rw-r--r--java/util/src/main/java/com/google/protobuf/util/JsonFormat.java17
1 files changed, 13 insertions, 4 deletions
diff --git a/java/util/src/main/java/com/google/protobuf/util/JsonFormat.java b/java/util/src/main/java/com/google/protobuf/util/JsonFormat.java
index 973f1517..955dfd86 100644
--- a/java/util/src/main/java/com/google/protobuf/util/JsonFormat.java
+++ b/java/util/src/main/java/com/google/protobuf/util/JsonFormat.java
@@ -50,6 +50,7 @@ import com.google.protobuf.Descriptors.Descriptor;
import com.google.protobuf.Descriptors.EnumDescriptor;
import com.google.protobuf.Descriptors.EnumValueDescriptor;
import com.google.protobuf.Descriptors.FieldDescriptor;
+import com.google.protobuf.Descriptors.FieldDescriptor.Type;
import com.google.protobuf.Descriptors.FileDescriptor;
import com.google.protobuf.Descriptors.OneofDescriptor;
import com.google.protobuf.DoubleValue;
@@ -1539,7 +1540,11 @@ public class JsonFormat {
Object key = parseFieldValue(keyField, new JsonPrimitive(entry.getKey()), entryBuilder);
Object value = parseFieldValue(valueField, entry.getValue(), entryBuilder);
if (value == null) {
- throw new InvalidProtocolBufferException("Map value cannot be null.");
+ if(ignoringUnknownFields && valueField.getType() == Type.ENUM) {
+ continue;
+ } else {
+ throw new InvalidProtocolBufferException("Map value cannot be null.");
+ }
}
entryBuilder.setField(keyField, key);
entryBuilder.setField(valueField, value);
@@ -1557,8 +1562,12 @@ public class JsonFormat {
for (int i = 0; i < array.size(); ++i) {
Object value = parseFieldValue(field, array.get(i), builder);
if (value == null) {
- throw new InvalidProtocolBufferException(
- "Repeated field elements cannot be null in field: " + field.getFullName());
+ if(ignoringUnknownFields && field.getType() == Type.ENUM) {
+ continue;
+ } else {
+ throw new InvalidProtocolBufferException(
+ "Repeated field elements cannot be null in field: " + field.getFullName());
+ }
}
builder.addRepeatedField(field, value);
}
@@ -1748,7 +1757,7 @@ public class JsonFormat {
// an exception later.
}
- if (result == null) {
+ if (result == null && !ignoringUnknownFields) {
throw new InvalidProtocolBufferException(
"Invalid enum value: " + value + " for enum type: " + enumDescriptor.getFullName());
}