Class JsonFormat.PrinterImpl
java.lang.Object
com.google.protobuf.util.JsonFormat.PrinterImpl
- Enclosing class:
JsonFormat
A Printer converts protobuf messages to the ProtoJSON format.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classprivate static interface -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final CharSequenceprivate final ExtensionRegistryprivate final JsonFormat.TextGeneratorprivate final com.google.gson.Gsonprivate final Set<Descriptors.FieldDescriptor> private final JsonFormat.TypeRegistryprivate final booleanprivate final booleanprivate final booleanprivate final TypeRegistryprivate static final String[]private final JsonFormat.ShouldPrintDefaultsprivate final booleanprivate static final Map<String, JsonFormat.PrinterImpl.WellKnownTypePrinter> -
Constructor Summary
ConstructorsConstructorDescriptionPrinterImpl(TypeRegistry registry, JsonFormat.TypeRegistry oldRegistry, ExtensionRegistry extensionRegistry, JsonFormat.ShouldPrintDefaults shouldPrintDefaults, Set<Descriptors.FieldDescriptor> includingDefaultValueFields, boolean preservingProtoFieldNames, Appendable jsonOutput, boolean omittingInsignificantWhitespace, boolean printingEnumsAsInts, boolean sortingMapKeys, boolean printingFullyQualifiedExtensionNames) -
Method Summary
Modifier and TypeMethodDescriptionprivate static Map<String, JsonFormat.PrinterImpl.WellKnownTypePrinter> private static StringgetReplacementOrNull(char c) If a character needs to be escaped, returns the replacement string.(package private) voidprint(MessageOrBuilder message) private voidprint(MessageOrBuilder message, String typeUrl) Prints a regular message with an optional type URL.private voidprintAny(MessageOrBuilder message) Prints google.protobuf.Anyprivate voidprintDuration(MessageOrBuilder message) Prints google.protobuf.Durationprivate voidprintField(Descriptors.FieldDescriptor field, Object value) private voidprintFieldMask(MessageOrBuilder message) Prints google.protobuf.FieldMaskprivate voidprintListValue(MessageOrBuilder message) Prints google.protobuf.ListValueprivate voidprintListValueConcrete(ListValueOrBuilder message) Prints `google.protobuf.ListValue` using the concrete generated type.private voidPrints `google.protobuf.ListValue` using reflection (generally only needed for DynamicMessage)private voidprintMapFieldValue(Descriptors.FieldDescriptor field, Object value) private voidprintRepeatedFieldValue(Descriptors.FieldDescriptor field, Object value) private voidprintSingleFieldValue(Descriptors.FieldDescriptor field, Object value) private voidprintSingleFieldValue(Descriptors.FieldDescriptor field, Object value, boolean alwaysWithQuotes) Prints a field's value in the ProtoJSON format.private voidPrints a string value wrapped in double quotes, escaping any illegal or dangerous characters for JSON safety.private voidprintStruct(MessageOrBuilder message) Prints google.protobuf.Structprivate voidprintStructConcrete(StructOrBuilder message) Prints the `google.protobuf.Struct` using the concrete generated class.private voidprintStructReflectively(MessageOrBuilder message) Prints the `google.protobuf.Struct` using reflection only.private voidprintTimestamp(MessageOrBuilder message) Prints google.protobuf.Timestampprivate voidprintValue(MessageOrBuilder message) Prints `google.protobuf.Value`.private voidprintValueConcrete(ValueOrBuilder message) Prints `google.protobuf.Value` using the concrete generated type.private voidprintValueReflectively(MessageOrBuilder message) Prints google.protobuf.Value using reflection (generally only needed for DynamicMessage)private voidprintWrapper(MessageOrBuilder message) Prints wrapper types (e.g., google.protobuf.Int32Value)private booleanprivate ByteStringtoByteString(MessageOrBuilder message)
-
Field Details
-
registry
-
oldRegistry
-
extensionRegistry
-
shouldPrintDefaults
-
includingDefaultValueFields
-
preservingProtoFieldNames
private final boolean preservingProtoFieldNames -
printingEnumsAsInts
private final boolean printingEnumsAsInts -
sortingMapKeys
private final boolean sortingMapKeys -
printingFullyQualifiedExtensionNames
private final boolean printingFullyQualifiedExtensionNames -
generator
-
gson
private final com.google.gson.Gson gson -
blankOrSpace
-
wellKnownTypePrinters
-
replacementChars
-
-
Constructor Details
-
PrinterImpl
PrinterImpl(TypeRegistry registry, JsonFormat.TypeRegistry oldRegistry, ExtensionRegistry extensionRegistry, JsonFormat.ShouldPrintDefaults shouldPrintDefaults, Set<Descriptors.FieldDescriptor> includingDefaultValueFields, boolean preservingProtoFieldNames, Appendable jsonOutput, boolean omittingInsignificantWhitespace, boolean printingEnumsAsInts, boolean sortingMapKeys, boolean printingFullyQualifiedExtensionNames)
-
-
Method Details
-
print
- Throws:
IOException
-
buildWellKnownTypePrinters
private static Map<String, JsonFormat.PrinterImpl.WellKnownTypePrinter> buildWellKnownTypePrinters() -
printAny
Prints google.protobuf.Any- Throws:
IOException
-
printWrapper
Prints wrapper types (e.g., google.protobuf.Int32Value)- Throws:
IOException
-
toByteString
-
printTimestamp
Prints google.protobuf.Timestamp- Throws:
IOException
-
printDuration
Prints google.protobuf.Duration- Throws:
IOException
-
printFieldMask
Prints google.protobuf.FieldMask- Throws:
IOException
-
printStruct
Prints google.protobuf.Struct- Throws:
IOException
-
printStructConcrete
Prints the `google.protobuf.Struct` using the concrete generated class.- Throws:
IOException
-
printStructReflectively
Prints the `google.protobuf.Struct` using reflection only. This should only be used for DynamicMessage usecases.- Throws:
IOException
-
printValue
Prints `google.protobuf.Value`.- Throws:
IOException
-
printValueConcrete
Prints `google.protobuf.Value` using the concrete generated type.- Throws:
IOException
-
printValueReflectively
Prints google.protobuf.Value using reflection (generally only needed for DynamicMessage)- Throws:
IOException
-
printListValue
Prints google.protobuf.ListValue- Throws:
IOException
-
printListValueConcrete
Prints `google.protobuf.ListValue` using the concrete generated type.- Throws:
IOException
-
printListValueReflectively
Prints `google.protobuf.ListValue` using reflection (generally only needed for DynamicMessage)- Throws:
IOException
-
shouldSpeciallyPrint
- Returns:
- Whether a set option means the corresponding field should be printed even if it normally wouldn't be.
-
print
Prints a regular message with an optional type URL.- Throws:
IOException
-
printField
- Throws:
IOException
-
printRepeatedFieldValue
private void printRepeatedFieldValue(Descriptors.FieldDescriptor field, Object value) throws IOException - Throws:
IOException
-
printMapFieldValue
- Throws:
IOException
-
printSingleFieldValue
private void printSingleFieldValue(Descriptors.FieldDescriptor field, Object value) throws IOException - Throws:
IOException
-
printSingleFieldValue
private void printSingleFieldValue(Descriptors.FieldDescriptor field, Object value, boolean alwaysWithQuotes) throws IOException Prints a field's value in the ProtoJSON format.- Parameters:
alwaysWithQuotes- whether to always add double-quotes to primitive types- Throws:
IOException
-
getReplacementOrNull
If a character needs to be escaped, returns the replacement string. Otherwise, returns null. -
printStringEscapedAndQuoted
Prints a string value wrapped in double quotes, escaping any illegal or dangerous characters for JSON safety.- Throws:
IOException
-