# Class JsonFormat.Printer (3.19.4)

    public static class JsonFormat.Printer

A Printer converts protobuf message to JSON format.

## Inheritance

[java.lang.Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \> JsonFormat.Printer

## Inherited Members

[Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) [Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) [Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) [Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) [Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) [Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) [Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) [Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) [Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) [Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) [Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)

## Methods

### appendTo(MessageOrBuilder message, Appendable output)

    public void appendTo(MessageOrBuilder message, Appendable output)

Converts a protobuf message to JSON format.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `message` | `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.MessageOrBuilder` |
| `output` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Appendable.html` |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` | if the message contains Any types that can't be resolved. |

### includingDefaultValueFields()

    public JsonFormat.Printer includingDefaultValueFields()

Creates a new 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
Printer.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.util.JsonFormat.Printer` |   |

### includingDefaultValueFields(Set\<Descriptors.FieldDescriptor\> fieldsToAlwaysOutput)

    public JsonFormat.Printer includingDefaultValueFields(Set<Descriptors.FieldDescriptor> fieldsToAlwaysOutput)

Creates a new 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 Printer. Call includingDefaultValueFields() with no args to unconditionally
output all fields.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `fieldsToAlwaysOutput` | `https://docs.oracle.com/javase/8/docs/api/java/util/Set.html<https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.Descriptors.FieldDescriptor>` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.util.JsonFormat.Printer` |   |

### omittingInsignificantWhitespace()

    public JsonFormat.Printer omittingInsignificantWhitespace()

Create a new 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 return

See <https://tools.ietf.org/html/rfc7159>
current Printer.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.util.JsonFormat.Printer` |   |

### preservingProtoFieldNames()

    public JsonFormat.Printer preservingProtoFieldNames()

Creates a new 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 Printer.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.util.JsonFormat.Printer` |   |

### print(MessageOrBuilder message)

    public String print(MessageOrBuilder message)

Converts a protobuf message to JSON format. Throws exceptions if there
are unknown Any types in the message.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `message` | `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.MessageOrBuilder` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.InvalidProtocolBufferException` |   |

### printingEnumsAsInts()

    public JsonFormat.Printer printingEnumsAsInts()

Creates a new Printer that will print enum field values as integers instead of as
string.
The new Printer clones all other configurations from the current
Printer.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.util.JsonFormat.Printer` |   |

### sortingMapKeys()

    public JsonFormat.Printer sortingMapKeys()

Create a new Printer that will sort the map keys 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 use 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.

This new Printer clones all other configurations from the current Printer.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.util.JsonFormat.Printer` |   |

### usingTypeRegistry(TypeRegistry registry)

    public JsonFormat.Printer usingTypeRegistry(TypeRegistry registry)

Creates a new Printer using the given registry. The new Printer clones all other
configurations from the current Printer.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `registry` | `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.TypeRegistry` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.util.JsonFormat.Printer` |   |

### usingTypeRegistry(JsonFormat.TypeRegistry oldRegistry)

    public JsonFormat.Printer usingTypeRegistry(JsonFormat.TypeRegistry oldRegistry)

Creates a new Printer using the given registry. The new Printer clones all other
configurations from the current Printer.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `oldRegistry` | `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.util.JsonFormat.TypeRegistry` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.util.JsonFormat.Printer` |   |