Skip to content

Add message option to serialize as well known JSON type#739

Open
martindam wants to merge 2 commits intogogo:masterfrom
martindam:well-known-types-option
Open

Add message option to serialize as well known JSON type#739
martindam wants to merge 2 commits intogogo:masterfrom
martindam:well-known-types-option

Conversation

@martindam
Copy link
Copy Markdown

@martindam martindam commented Oct 21, 2021

This is a suggested implementation of #738

With this diff it is possible to mark that a message should be JSON marshalled as a well known type

Without jsonwkt option:

message UUID {
	string value = 1;
}
message MyType {
	UUID user_uuid = 1;
}

MyType would be serialized to JSON as:

{
	"user_uuid": {
		"value": "8dfab8c2-7916-477f-bbd6-c9fc00dc4158"
	}
}

With jsonwkt option

message UUID {
	option (gogoproto.json_well_known_type) = "StringValue";
	string value = 1;
}
message MyType {
	UUID user_uuid = 1;
}

MyType would be serialized to JSON as:

{
	"user_uuid": "8dfab8c2-7916-477f-bbd6-c9fc00dc4158"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant