Class JsonParser (3.15.8)

public sealed class JsonParser : object

Reflection-based converter from JSON to messages.

Inheritance

Object > JsonParser

Namespace

Google.Protobuf

Assembly

Google.Protobuf.dll

Remarks

Instances of this class are thread-safe, with no mutable state.

This is a simple start to get JSON parsing working. As it's reflection-based, it's not as quick as baking calls into generated messages - but is a simpler implementation. (This code is generally not heavily optimized.)

Constructors

JsonParser(JsonParser.Settings)

public JsonParser(JsonParser.Settings settings)

Creates a new formatted with the given settings.

Parameter
NameDescription
settingsJsonParser.Settings

The settings.

Properties

Default

public static JsonParser Default { get; }

Returns a formatter using the default settings.

Property Value
TypeDescription
JsonParser

Methods

Parse(String, MessageDescriptor)

public IMessage Parse(string json, MessageDescriptor descriptor)

Parses json into a new message.

Parameters
NameDescription
jsonString

The JSON to parse.

descriptorMessageDescriptor

Descriptor of message type to parse.

Returns
TypeDescription
IMessage
Exceptions
TypeDescription
InvalidJsonException

The JSON does not comply with RFC 7159

InvalidProtocolBufferException

The JSON does not represent a Protocol Buffers message correctly

Parse(TextReader, MessageDescriptor)

public IMessage Parse(TextReader jsonReader, MessageDescriptor descriptor)

Parses JSON read from jsonReader into a new message.

Parameters
NameDescription
jsonReaderTextReader

Reader providing the JSON to parse.

descriptorMessageDescriptor

Descriptor of message type to parse.

Returns
TypeDescription
IMessage
Exceptions
TypeDescription
InvalidJsonException

The JSON does not comply with RFC 7159

InvalidProtocolBufferException

The JSON does not represent a Protocol Buffers message correctly

Parse<T>(String)

public T Parse<T>(string json)
    where T : IMessage, new()

Parses json into a new message.

Parameter
NameDescription
jsonString

The JSON to parse.

Returns
TypeDescription
T
Type Parameter
NameDescription
T

The type of message to create.

Exceptions
TypeDescription
InvalidJsonException

The JSON does not comply with RFC 7159

InvalidProtocolBufferException

The JSON does not represent a Protocol Buffers message correctly

Parse<T>(TextReader)

public T Parse<T>(TextReader jsonReader)
    where T : IMessage, new()

Parses JSON read from jsonReader into a new message.

Parameter
NameDescription
jsonReaderTextReader

Reader providing the JSON to parse.

Returns
TypeDescription
T
Type Parameter
NameDescription
T

The type of message to create.

Exceptions
TypeDescription
InvalidJsonException

The JSON does not comply with RFC 7159

InvalidProtocolBufferException

The JSON does not represent a Protocol Buffers message correctly