Class JsonFormat.PrinterImpl

  • Enclosing class:
    JsonFormat

    private static final class JsonFormat.PrinterImpl
    extends java.lang.Object
    A Printer converts protobuf messages to the ProtoJSON format.
    • Field Detail

      • preservingProtoFieldNames

        private final boolean preservingProtoFieldNames
      • printingEnumsAsInts

        private final boolean printingEnumsAsInts
      • sortingMapKeys

        private final boolean sortingMapKeys
      • printingFullyQualifiedExtensionNames

        private final boolean printingFullyQualifiedExtensionNames
      • gson

        private final com.google.gson.Gson gson
      • blankOrSpace

        private final java.lang.CharSequence blankOrSpace
      • replacementChars

        private static final java.lang.String[] replacementChars
    • Method Detail

      • print

        void print​(MessageOrBuilder message)
            throws java.io.IOException
        Throws:
        java.io.IOException
      • printAny

        private void printAny​(MessageOrBuilder message)
                       throws java.io.IOException
        Prints google.protobuf.Any
        Throws:
        java.io.IOException
      • printWrapper

        private void printWrapper​(MessageOrBuilder message)
                           throws java.io.IOException
        Prints wrapper types (e.g., google.protobuf.Int32Value)
        Throws:
        java.io.IOException
      • printTimestamp

        private void printTimestamp​(MessageOrBuilder message)
                             throws java.io.IOException
        Prints google.protobuf.Timestamp
        Throws:
        java.io.IOException
      • printDuration

        private void printDuration​(MessageOrBuilder message)
                            throws java.io.IOException
        Prints google.protobuf.Duration
        Throws:
        java.io.IOException
      • printFieldMask

        private void printFieldMask​(MessageOrBuilder message)
                             throws java.io.IOException
        Prints google.protobuf.FieldMask
        Throws:
        java.io.IOException
      • printStruct

        private void printStruct​(MessageOrBuilder message)
                          throws java.io.IOException
        Prints google.protobuf.Struct
        Throws:
        java.io.IOException
      • printStructConcrete

        private void printStructConcrete​(StructOrBuilder message)
                                  throws java.io.IOException
        Prints the `google.protobuf.Struct` using the concrete generated class.
        Throws:
        java.io.IOException
      • printStructReflectively

        private void printStructReflectively​(MessageOrBuilder message)
                                      throws java.io.IOException
        Prints the `google.protobuf.Struct` using reflection only. This should only be used for DynamicMessage usecases.
        Throws:
        java.io.IOException
      • printValue

        private void printValue​(MessageOrBuilder message)
                         throws java.io.IOException
        Prints `google.protobuf.Value`.
        Throws:
        java.io.IOException
      • printValueConcrete

        private void printValueConcrete​(ValueOrBuilder message)
                                 throws java.io.IOException
        Prints `google.protobuf.Value` using the concrete generated type.
        Throws:
        java.io.IOException
      • printValueReflectively

        private void printValueReflectively​(MessageOrBuilder message)
                                     throws java.io.IOException
        Prints google.protobuf.Value using reflection (generally only needed for DynamicMessage)
        Throws:
        java.io.IOException
      • printListValue

        private void printListValue​(MessageOrBuilder message)
                             throws java.io.IOException
        Prints google.protobuf.ListValue
        Throws:
        java.io.IOException
      • printListValueConcrete

        private void printListValueConcrete​(ListValueOrBuilder message)
                                     throws java.io.IOException
        Prints `google.protobuf.ListValue` using the concrete generated type.
        Throws:
        java.io.IOException
      • printListValueReflectively

        private void printListValueReflectively​(MessageOrBuilder message)
                                         throws java.io.IOException
        Prints `google.protobuf.ListValue` using reflection (generally only needed for DynamicMessage)
        Throws:
        java.io.IOException
      • shouldSpeciallyPrint

        private boolean shouldSpeciallyPrint​(Descriptors.FieldDescriptor field)
        Returns:
        Whether a set option means the corresponding field should be printed even if it normally wouldn't be.
      • print

        private void print​(MessageOrBuilder message,
                           @Nullable
                           java.lang.String typeUrl)
                    throws java.io.IOException
        Prints a regular message with an optional type URL.
        Throws:
        java.io.IOException
      • printField

        private void printField​(Descriptors.FieldDescriptor field,
                                java.lang.Object value)
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • printRepeatedFieldValue

        private void printRepeatedFieldValue​(Descriptors.FieldDescriptor field,
                                             java.lang.Object value)
                                      throws java.io.IOException
        Throws:
        java.io.IOException
      • printMapFieldValue

        private void printMapFieldValue​(Descriptors.FieldDescriptor field,
                                        java.lang.Object value)
                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • printSingleFieldValue

        private void printSingleFieldValue​(Descriptors.FieldDescriptor field,
                                           java.lang.Object value)
                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • printSingleFieldValue

        private void printSingleFieldValue​(Descriptors.FieldDescriptor field,
                                           java.lang.Object value,
                                           boolean alwaysWithQuotes)
                                    throws java.io.IOException
        Prints a field's value in the ProtoJSON format.
        Parameters:
        alwaysWithQuotes - whether to always add double-quotes to primitive types
        Throws:
        java.io.IOException
      • getReplacementOrNull

        private static java.lang.String getReplacementOrNull​(char c)
        If a character needs to be escaped, returns the replacement string. Otherwise, returns null.
      • printStringEscapedAndQuoted

        private void printStringEscapedAndQuoted​(java.lang.CharSequence value)
                                          throws java.io.IOException
        Prints a string value wrapped in double quotes, escaping any illegal or dangerous characters for JSON safety.
        Throws:
        java.io.IOException