Google.Protobuf.JsonParser

Reflection-based converter from JSON to messages.

Summary

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 and Destructors

JsonParser(Settings settings)
Creates a new formatted with the given settings.

Properties

Default
Returns a formatter using the default settings.

Public functions

Parse(string json, MessageDescriptor descriptor)
Parses json into a new message.
Parse(TextReader jsonReader, MessageDescriptor descriptor)
Parses JSON read from jsonReader into a new message.
Parse< T >(string json)
T
Parses json into a new message.
Parse< T >(TextReader jsonReader)
T
Parses JSON read from jsonReader into a new message.

Classes

Google.Protobuf.JsonParser.Settings

Settings controlling JSON parsing.

Properties

Default

JsonParser Default

Returns a formatter using the default settings.

Public functions

JsonParser

 JsonParser(
  Settings settings
)

Creates a new formatted with the given settings.

Details
Parameters
settings
The settings.

Parse

IMessage Parse(
  string json,
  MessageDescriptor descriptor
)

Parses json into a new message.

Details
Parameters
json
The JSON to parse.
descriptor
Descriptor of message type to parse.
Exceptions
InvalidJsonException
The JSON does not comply with RFC 7159
InvalidProtocolBufferException
The JSON does not represent a Protocol Buffers message correctly

Parse

IMessage Parse(
  TextReader jsonReader,
  MessageDescriptor descriptor
)

Parses JSON read from jsonReader into a new message.

Details
Parameters
jsonReader
Reader providing the JSON to parse.
descriptor
Descriptor of message type to parse.
Exceptions
InvalidJsonException
The JSON does not comply with RFC 7159
InvalidProtocolBufferException
The JSON does not represent a Protocol Buffers message correctly

Parse< T >

T Parse< T >(
  string json
)

Parses json into a new message.

Details
Template Parameters
T
The type of message to create.
Parameters
json
The JSON to parse.
Exceptions
InvalidJsonException
The JSON does not comply with RFC 7159
InvalidProtocolBufferException
The JSON does not represent a Protocol Buffers message correctly

Parse< T >

T Parse< T >(
  TextReader jsonReader
)

Parses JSON read from jsonReader into a new message.

Details
Template Parameters
T
The type of message to create.
Parameters
jsonReader
Reader providing the JSON to parse.
Exceptions
InvalidJsonException
The JSON does not comply with RFC 7159
InvalidProtocolBufferException
The JSON does not represent a Protocol Buffers message correctly