Class JsonFormatter.Settings (3.23.0)

public sealed class JsonFormatter.Settings

Settings controlling JSON formatting.

Inheritance

object > JsonFormatter.Settings

Namespace

Google.Protobuf

Assembly

Google.Protobuf.dll

Constructors

Settings(bool)

public Settings(bool formatDefaultValues)

Creates a new JsonFormatter.Settings object with the specified formatting of default values and an empty type registry.

Parameter
NameDescription
formatDefaultValuesbool

true if default values (0, empty strings etc) should be formatted; false otherwise.

Settings(bool, TypeRegistry)

public Settings(bool formatDefaultValues, TypeRegistry typeRegistry)

Creates a new JsonFormatter.Settings object with the specified formatting of default values and type registry.

Parameters
NameDescription
formatDefaultValuesbool

true if default values (0, empty strings etc) should be formatted; false otherwise.

typeRegistryTypeRegistry

The TypeRegistry to use when formatting Any messages.

Properties

Default

public static JsonFormatter.Settings Default { get; }

Default settings, as used by Default

Property Value
TypeDescription
JsonFormatterSettings

FormatDefaultValues

public bool FormatDefaultValues { get; }

Whether fields which would otherwise not be included in the formatted data should be formatted even when the value is not present, or has the default value. This option only affects fields which don't support "presence" (e.g. singular non-optional proto3 primitive fields).

Property Value
TypeDescription
bool

FormatEnumsAsIntegers

public bool FormatEnumsAsIntegers { get; }

Whether to format enums as ints. Defaults to false.

Property Value
TypeDescription
bool

Indentation

public string Indentation { get; }

Indentation string, used for formatting. Setting null disables indentation.

Property Value
TypeDescription
string

PreserveProtoFieldNames

public bool PreserveProtoFieldNames { get; }

Whether to use the original proto field names as defined in the .proto file. Defaults to false.

Property Value
TypeDescription
bool

TypeRegistry

public TypeRegistry TypeRegistry { get; }

The type registry used to format Any messages.

Property Value
TypeDescription
TypeRegistry

Methods

WithFormatDefaultValues(bool)

public JsonFormatter.Settings WithFormatDefaultValues(bool formatDefaultValues)

Creates a new JsonFormatter.Settings object with the specified formatting of default values and the current settings.

Parameter
NameDescription
formatDefaultValuesbool

true if default values (0, empty strings etc) should be formatted; false otherwise.

Returns
TypeDescription
JsonFormatterSettings

WithFormatEnumsAsIntegers(bool)

public JsonFormatter.Settings WithFormatEnumsAsIntegers(bool formatEnumsAsIntegers)

Creates a new JsonFormatter.Settings object with the specified enums formatting option and the current settings.

Parameter
NameDescription
formatEnumsAsIntegersbool

true to format the enums as integers; false to format enums as enum names.

Returns
TypeDescription
JsonFormatterSettings

WithIndentation(string)

public JsonFormatter.Settings WithIndentation(string indentation = "  ")

Creates a new JsonFormatter.Settings object with the specified indentation and the current settings.

Parameter
NameDescription
indentationstring

The string to output for each level of indentation (nesting). The default is two spaces per level. Use null to disable indentation entirely.

Returns
TypeDescription
JsonFormatterSettings
Remarks

A non-null value for Indentation will insert additional line-breaks to the JSON output. Each line will contain either a single value, or braces. The default line-break is determined by NewLine, which is "\n" on Unix platforms, and "\r\n" on Windows. If JsonFormatter seems to produce empty lines, you need to pass a TextWriter that uses a "\n" newline. See Format(IMessage, TextWriter).

WithPreserveProtoFieldNames(bool)

public JsonFormatter.Settings WithPreserveProtoFieldNames(bool preserveProtoFieldNames)

Creates a new JsonFormatter.Settings object with the specified field name formatting option and the current settings.

Parameter
NameDescription
preserveProtoFieldNamesbool

true to preserve proto field names; false to convert them to lowerCamelCase.

Returns
TypeDescription
JsonFormatterSettings

WithTypeRegistry(TypeRegistry)

public JsonFormatter.Settings WithTypeRegistry(TypeRegistry typeRegistry)

Creates a new JsonFormatter.Settings object with the specified type registry and the current settings.

Parameter
NameDescription
typeRegistryTypeRegistry

The TypeRegistry to use when formatting Any messages.

Returns
TypeDescription
JsonFormatterSettings