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

only allow to convert root array to single repeated pb #2035

Merged
merged 1 commit into from
Dec 5, 2022

Conversation

chenBright
Copy link
Contributor

@chenBright chenBright commented Dec 4, 2022

What problem does this PR solve?

Issue Number:

Problem Summary:
目前打开single_repeated_to_array开关后,pb转json只支持root case,但是打开array_to_single_repeated开关,json转pb没有限制root case。这样会导致json转pb,pb再转回json,前后的json结构发生了变化,不符合预期。例如:

# pb
meesage Single {
    repeated int ids;
}

message Test {
    Single single;
}

# 打开array_to_single_repeated开关后,以下json可以转为Test
{
    "single": [1,2,3]
}

# 但是打开single_repeated_to_array开关后,Test转为json的格式为:
{
    single: {
        "ids": [1,2,3]
    }
}

What is changed and the side effects?

Changed:

Side effects:

  • Performance effects(性能影响):

  • Breaking backward compatibility(向后兼容性): 如果旧代码希望array_to_single_repeated将非root array转成single @repedted的话,使用此PR代码后,会导致json转pb失败。


Check List:

  • Please make sure your changes are compilable(请确保你的更改可以通过编译).
  • When providing us with a new feature, it is best to add related tests(如果你向我们增加一个新的功能, 请添加相关测试).
  • Please follow Contributor Covenant Code of Conduct.(请遵循贡献者准则).

@chenBright chenBright requested a review from wasphin December 4, 2022 14:42
Copy link
Member

@wasphin wasphin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@wasphin
Copy link
Member

wasphin commented Dec 4, 2022

What problem does this PR solve?

Issue Number:

Problem Summary: 目前打开single_repeated_to_array开关后,pb转json只支持root case,但是打开array_to_single_repeated开关,json转pb没有限制root case。这样会导致json转pb,pb再转回json,前后的json结构发生了变化,不符合预期。例如:

# pb
meesage Single {
    repeated int ids;
}

message Test {
    Single single;
}

# 打开array_to_single_repeated开关后,以下json可以转为Test
{
    "ids": [1,2,3]
}

这个可以转为 Test? 感觉转换后应该是空 Test,看代码应该是从 json 中查找 field 进行转换,找不到 single 不应该进入到内层。
例子里 ids 是不是应该是 single?

@chenBright
Copy link
Contributor Author

What problem does this PR solve?

Issue Number:
Problem Summary: 目前打开single_repeated_to_array开关后,pb转json只支持root case,但是打开array_to_single_repeated开关,json转pb没有限制root case。这样会导致json转pb,pb再转回json,前后的json结构发生了变化,不符合预期。例如:

# pb
meesage Single {
    repeated int ids;
}

message Test {
    Single single;
}

# 打开array_to_single_repeated开关后,以下json可以转为Test
{
    "ids": [1,2,3]
}

这个可以转为 Test? 感觉转换后应该是空 Test,看代码应该是从 json 中查找 field 进行转换,找不到 single 不应该进入到内层。 例子里 ids 是不是应该是 single?

嗯嗯,确实写错了,应该是single。

@wwbmmm wwbmmm merged commit 4f59bc6 into apache:master Dec 5, 2022
@chenBright chenBright deleted the root_single_array branch December 5, 2022 02:50
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.

3 participants