public static class JsonFormat.Printer extends Object
Modifier and Type | Method and Description |
---|---|
void |
appendTo(MessageOrBuilder message,
Appendable output)
Converts a protobuf message to JSON format.
|
JsonFormat.Printer |
includingDefaultValueFields()
Creates a new
JsonFormat.Printer that will also print fields set to their
defaults. |
JsonFormat.Printer |
includingDefaultValueFields(Set<Descriptors.FieldDescriptor> fieldsToAlwaysOutput)
Creates a new
JsonFormat.Printer that will also print default-valued fields if their
FieldDescriptors are found in the supplied set. |
JsonFormat.Printer |
omittingInsignificantWhitespace()
Create a new
JsonFormat.Printer that will omit all insignificant whitespace in the JSON output. |
JsonFormat.Printer |
preservingProtoFieldNames()
Creates a new
JsonFormat.Printer that is configured to use the original proto
field names as defined in the .proto file rather than converting them to
lowerCamelCase. |
String |
print(MessageOrBuilder message)
Converts a protobuf message to JSON format.
|
JsonFormat.Printer |
printingEnumsAsInts()
Creates a new
JsonFormat.Printer that will print enum field values as integers instead of as
string. |
JsonFormat.Printer |
usingTypeRegistry(JsonFormat.TypeRegistry registry)
Creates a new
JsonFormat.Printer using the given registry. |
public JsonFormat.Printer usingTypeRegistry(JsonFormat.TypeRegistry registry)
JsonFormat.Printer
using the given registry. The new Printer
clones all other configurations from the current JsonFormat.Printer
.IllegalArgumentException
- if a registry is already set.public JsonFormat.Printer includingDefaultValueFields()
JsonFormat.Printer
that will also print fields set to their
defaults. Empty repeated fields and map fields will be printed as well.
The new Printer clones all other configurations from the current
JsonFormat.Printer
.public JsonFormat.Printer printingEnumsAsInts()
JsonFormat.Printer
that will print enum field values as integers instead of as
string.
The new Printer clones all other configurations from the current
JsonFormat.Printer
.public JsonFormat.Printer includingDefaultValueFields(Set<Descriptors.FieldDescriptor> fieldsToAlwaysOutput)
JsonFormat.Printer
that will also print default-valued fields if their
FieldDescriptors are found in the supplied set. Empty repeated fields and map fields will be
printed as well, if they match. The new Printer clones all other configurations from the
current JsonFormat.Printer
. Call includingDefaultValueFields() with no args to unconditionally
output all fields.public JsonFormat.Printer preservingProtoFieldNames()
JsonFormat.Printer
that is configured to use the original proto
field names as defined in the .proto file rather than converting them to
lowerCamelCase. The new Printer clones all other configurations from the
current JsonFormat.Printer
.public JsonFormat.Printer omittingInsignificantWhitespace()
JsonFormat.Printer
that will omit all insignificant whitespace in the JSON output.
This new Printer clones all other configurations from the current Printer. 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 returnSee https://tools.ietf.org/html/rfc7159 current
JsonFormat.Printer
.public void appendTo(MessageOrBuilder message, Appendable output) throws IOException
InvalidProtocolBufferException
- if the message contains Any types that can't be
resolved.IOException
- if writing to the output fails.public String print(MessageOrBuilder message) throws InvalidProtocolBufferException
InvalidProtocolBufferException
Copyright © 2008–2020. All rights reserved.