rocketmq: Fetch Cluster information json data when parse in golang occure:invalid character '0' looking for beginning of object key string
BUG REPORT
When I use rocketmq-client-go fetch cluster information ,then i get the json data is:
{"brokerAddrTable":{"broker_37_master":{"brokerAddrs":{0:"172.16.16.37:10911"},"brokerName":"broker_37_master","cluster":"37_cluster"}},"clusterAddrTable":{"37_cluster":["broker_37_master"]}}
then the golang json parse occure error:
err := json.Unmarshal(response, &temp)
and the error information is:
invalid character '0' looking for beginning of object key string
but JSON key must be string!
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 16 (5 by maintainers)
Commits related to this issue
- fix(json_int_key): fix issue there are int keys in JSON Related to https://github.com/apache/rocketmq/issues/3369 — committed to Tomilla/rocketmq-client-go by deleted user 10 months ago
- fix(json_int_key): fix issue there are int keys in JSON Related to https://github.com/apache/rocketmq/issues/3369 — committed to Tomilla/rocketmq-client-go by Tomilla 10 months ago
@liuxuzxx 这个问题直接修改协议容易引起不兼容问题,可通过编写json解析代码规避,参考 https://github.com/apache/rocketmq-client-go/blob/master/internal/route.go#L533
看到RocketMQ相关序列化组件使用的是fastjson,去fastjson下查看了下相关的issule,例如这个:https://github.com/alibaba/fastjson/issues/3821 但是好像作者并没有回应这个问题也没有关闭,不知道这个是不是fastjson的一个问题,fastjson在Map<Integer,xxx> 这种形式的序列化确实会存在不符合json规范定义的情况(目前搜索到的json规范定义要求key是string类型),也看到讨论的issule,但是作者好像没有做回复,目前找到一种方案如下:
不知道rocketmq要是这样子修改会有多大改动,只是感觉现在的这个json形式不符合规范!
brokerAddrs":{0:“172.16.16.37:10911”} 地址这里也有冒号,导致解析失败的,将这里的key设置为string,就可以避免这个问题