|
|
|
@ -49,6 +49,7 @@ import com.google.protobuf.Descriptors.EnumDescriptor; |
|
|
|
|
import com.google.protobuf.Descriptors.EnumValueDescriptor; |
|
|
|
|
import com.google.protobuf.Descriptors.FieldDescriptor; |
|
|
|
|
import com.google.protobuf.Descriptors.FileDescriptor; |
|
|
|
|
import com.google.protobuf.Descriptors.OneofDescriptor; |
|
|
|
|
import com.google.protobuf.DoubleValue; |
|
|
|
|
import com.google.protobuf.Duration; |
|
|
|
|
import com.google.protobuf.DynamicMessage; |
|
|
|
@ -782,12 +783,18 @@ public class JsonFormat { |
|
|
|
|
if (includingDefaultValueFields) { |
|
|
|
|
fieldsToPrint = new TreeMap<FieldDescriptor, Object>(); |
|
|
|
|
for (FieldDescriptor field : message.getDescriptorForType().getFields()) { |
|
|
|
|
if (field.isOptional() |
|
|
|
|
&& field.getJavaType() == FieldDescriptor.JavaType.MESSAGE |
|
|
|
|
&& !message.hasField(field)) { |
|
|
|
|
// Always skip empty optional message fields. If not we will recurse indefinitely if
|
|
|
|
|
// a message has itself as a sub-field.
|
|
|
|
|
continue; |
|
|
|
|
if (field.isOptional()) { |
|
|
|
|
if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE |
|
|
|
|
&& !message.hasField(field)){ |
|
|
|
|
// Always skip empty optional message fields. If not we will recurse indefinitely if
|
|
|
|
|
// a message has itself as a sub-field.
|
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
OneofDescriptor oneof = field.getContainingOneof(); |
|
|
|
|
if (oneof != null && !message.hasField(field)) { |
|
|
|
|
// Skip all oneof fields except the one that is actually set
|
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
fieldsToPrint.put(field, message.getField(field)); |
|
|
|
|
} |
|
|
|
|