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
Name Description
formatDefaultValues bool

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
Name Description
formatDefaultValues bool

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

typeRegistry TypeRegistry

The TypeRegistry to use when formatting Any messages.

Properties

Default

public static JsonFormatter.Settings Default { get; }

Default settings, as used by Default

Property Value
Type Description
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
Type Description
bool

FormatEnumsAsIntegers

public bool FormatEnumsAsIntegers { get; }

Whether to format enums as ints. Defaults to false.

Property Value
Type Description
bool

Indentation

public string Indentation { get; }

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

Property Value
Type Description
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
Type Description
bool

TypeRegistry

public TypeRegistry TypeRegistry { get; }

The type registry used to format Any messages.

Property Value
Type Description
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
Name Description
formatDefaultValues bool

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

Returns
Type Description
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
Name Description
formatEnumsAsIntegers bool

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

Returns
Type Description
JsonFormatterSettings

WithIndentation(string)

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

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

Parameter
Name Description
indentation string

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

Returns
Type Description
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
Name Description
preserveProtoFieldNames bool

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

Returns
Type Description
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
Name Description
typeRegistry TypeRegistry

The TypeRegistry to use when formatting Any messages.

Returns
Type Description
JsonFormatterSettings