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

[ISSUE #845] support standard json #846

Merged
merged 1 commit into from
Aug 23, 2022
Merged

[ISSUE #845] support standard json #846

merged 1 commit into from
Aug 23, 2022

Conversation

yuz10
Copy link
Member

@yuz10 yuz10 commented Jun 16, 2022

What is the purpose of the change

#845

because apache/rocketmq#4432 change route info to standard json such as:
{"brokerDatas":[{"brokerAddrs":{"0":"127.0.0.1:10911"}]}
the old is:
{"brokerDatas":[{"brokerAddrs":{0:"127.0.0.1:10911"}]}

Brief changelog

XX

Verifying this change

XXXX

Follow this checklist to help us incorporate your contribution quickly and easily. Notice, it would be helpful if you could finish the following 5 checklist(the last one is not necessary)before request the community to review your PR.

  • Make sure there is a Github issue filed for the change (usually before you start working on it). Trivial changes like typos do not require a Github issue. Your pull request should address just this issue, without pulling in other changes - one PR resolves one issue.
  • Format the pull request title like [ISSUE #123] Fix UnknownException when host config not exist. Each commit in the pull request should have a meaningful subject line and body.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Write necessary unit-test(over 80% coverage) to verify your logic correction, more mock a little better when a cross-module dependency exists.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

@lizhanhui
Copy link

Is it possible to change the deserialization workflow as follows?

  1. Attempt to parse the response JSON using standard go JSON library;
  2. Check and catch potential errors, fallback to manual parsing if invalid contents are found;

@@ -558,7 +558,8 @@ func (routeData *TopicRouteData) decode(data string) error {
if i < 0 {
continue
}
id, _ := strconv.ParseInt(str[0:i], 10, 64)
brokerId := strings.ReplaceAll(str[0:i], "\"", "")
id, _ := strconv.ParseInt(brokerId, 10, 64)
Copy link
Member

Choose a reason for hiding this comment

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

Can we deserialize JSON string in a standard way? Make the SDK could handle both the two formats.

Copy link
Member Author

Choose a reason for hiding this comment

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

I am afraid we cant use the standard way because the json is not standard, the change have already handled both stardard hand non-stardard formats

@yuz10
Copy link
Member Author

yuz10 commented Jun 17, 2022

Is it possible to change the deserialization workflow as follows?

  1. Attempt to parse the response JSON using standard go JSON library;
  2. Check and catch potential errors, fallback to manual parsing if invalid contents are found;

I think it is worthless to Attempt the first time to parse standard json, because in most case it will fail. the manual code is ugly but unfortunately we cant remove it, and its solid.

@ShannonDing ShannonDing added the discuss Something undering disscussing label Jul 22, 2022
Copy link
Member

@ShannonDing ShannonDing left a comment

Choose a reason for hiding this comment

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

according to apache/rocketmq#4471 , i will close this pr first.

@lizhanhui lizhanhui reopened this Aug 17, 2022
@lizhanhui
Copy link

@yuz10 I am assuming this pull request works for both standard and illegal JSON responses. Right?

@ShannonDing ShannonDing added the enhancement New feature or request label Aug 23, 2022
@ShannonDing ShannonDing reopened this Aug 23, 2022
@ShannonDing ShannonDing merged commit c9ca891 into master Aug 23, 2022
@yuz10 yuz10 deleted the yuz10-patch-1 branch October 22, 2022 11:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discuss Something undering disscussing enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

support standard json format when update route from nameserver
4 participants