Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Reopened] Incorrect json serialization of empty StringValue #6667

Closed
serhiikushch opened this issue Sep 18, 2019 · 5 comments · Fixed by #6713
Closed

[Reopened] Incorrect json serialization of empty StringValue #6667

serhiikushch opened this issue Sep 18, 2019 · 5 comments · Fixed by #6713

Comments

@serhiikushch
Copy link

serhiikushch commented Sep 18, 2019

What version of protobuf and what language are you using?
Version: v3.9.1.
Language: PHP 7.3

What operating system (Linux, Windows, ...) and version?
Linux

What did you do?
I have a message defined as following:

syntax = "proto3";
package generated;

import "google/protobuf/wrappers.proto";

message Foo {
    Bar bar = 1;
}

message Bar {
    google.protobuf.StringValue field = 1;
}

What did you expect to see
When converting this message to json string like:

$message = new Foo(['bar' => new Bar(['field' => ''])])
echo $message->serializeToJsonString();

should return:

{"bar":{"field":""}}

What did you see instead?

{"bar":{"field":}}

that results in Syntax error after applying json_decode

Anything else we should know about your project / environment
I'm using c extension, however php package does not have this issue.
Detailed example with tests and docker file https://github.com/serhiikushch/protobuf-issue

@Sixuan
Copy link

Sixuan commented Sep 30, 2019

Anyone can take a look at this issue? We've heard aa bunch of people that are having the same issue and had to switch to a different library.

Thanks!

@TeBoring
Copy link
Contributor

testSerialize(string $expected, \Google\Protobuf\Internal\Message $message)

Does changing \Google\Protobuf\Internal\Message to the actual type solve the problem?

@TeBoring
Copy link
Contributor

Seems the problem is because the array constructor with StringValue has some problems.
For now, could you use setter to set value?

@serhiikushch
Copy link
Author

testSerialize(string $expected, \Google\Protobuf\Internal\Message $message)

Does changing \Google\Protobuf\Internal\Message to the actual type solve the problem?

No it's just type checking and changing it does not have any impact on functionality

Seems the problem is because the array constructor with StringValue has some problems.
For now, could you use setter to set value?

unfortunately not. we faced this issue on serializing GRPC service response(message structure is similar to my example)

TeBoring added a commit to TeBoring/protobuf that referenced this issue Sep 30, 2019
@TeBoring
Copy link
Contributor

Fixed in #6713

TeBoring added a commit that referenced this issue Sep 30, 2019
* Initialize well known type values

Also fixes #6667

* Revert unwanted change
TeBoring added a commit to TeBoring/protobuf that referenced this issue Sep 30, 2019
* Initialize well known type values

Also fixes protocolbuffers#6667

* Revert unwanted change
TeBoring added a commit that referenced this issue Sep 30, 2019
* Initialize well known type values

Also fixes #6667

* Revert unwanted change
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 a pull request may close this issue.

3 participants