Class MessageMarshaller.Builder

    • Method Detail

      • register

        public MessageMarshaller.Builder register​(com.google.protobuf.Message prototype)
        Registers the type of the provided Message for use with the created MessageMarshaller. While any instance of the type to register can be used, this will commonly be called with getDefaultInstance() on the type to register.

        The provided Message and all nested Message types reachable from this one will be registered and available for marshalling. For clarity, it's generally a good idea to explicitly register any Message that you will pass to methods of MessageMarshaller even if they are already registered as a nested Message.

      • register

        public MessageMarshaller.Builder register​(java.lang.Class<? extends com.google.protobuf.Message> messageClass)
        Registers the provided Message type for use with the created MessageMarshaller. While any instance of the type to register can be used, this will commonly be called with getDefaultInstance() on the type to register.

        The provided Message and all nested Message types reachable from this one will be registered and available for marshalling. For clarity, it's generally a good idea to explicitly register any Message that you will pass to methods of MessageMarshaller even if they are already registered as a nested Message.

      • includingDefaultValueFields

        public MessageMarshaller.Builder includingDefaultValueFields​(boolean includingDefaultValueFields)
        Set whether unset fields will be serialized with their default values. Empty repeated fields and map fields will be printed as well. The new Printer clones all other configurations from the current.
      • preservingProtoFieldNames

        public MessageMarshaller.Builder preservingProtoFieldNames​(boolean preservingProtoFieldNames)
        Set whether field names should use the original name in the .proto file instead of converting to lowerCamelCase when serializing messages. When set, the json_name annotation will be ignored.
      • omittingInsignificantWhitespace

        public MessageMarshaller.Builder omittingInsignificantWhitespace​(boolean omittingInsignificantWhitespace)
        Whether the serialized JSON output will omit all insignificant whitespace. Insignificant whitespace is defined by the JSON spec as whitespace that appear between JSON structural elements:
         ws = *(
         %x20 /              ; Space
         %x09 /              ; Horizontal tab
         %x0A /              ; Line feed or New line
         %x0D )              ; Carriage return
         
        See https://tools.ietf.org/html/rfc7159
      • ignoringUnknownFields

        public MessageMarshaller.Builder ignoringUnknownFields​(boolean ignoringUnknownFields)
        Sets whether unknown fields should be allowed when parsing JSON input. When not set, an exception will be thrown when encountering unknown fields.
      • printingEnumsAsInts

        public MessageMarshaller.Builder printingEnumsAsInts​(boolean printingEnumsAsInts)
        Sets whether enum values should be printed as their integer value rather than their name.
      • sortingMapKeys

        public MessageMarshaller.Builder sortingMapKeys​(boolean sortingMapKeys)
        Sets whether map keys will be sorted in the JSON output.

        Use of this modifier is discouraged, the generated JSON messages are equivalent with and without this option set, but there are some corner caseuse cases that demand a stable output, while order of map keys is otherwise arbitrary.

        The generated order is not well-defined and should not be depended on, but it's stable.