Frodez opened a new issue #3389: URL: https://github.com/apache/rocketmq/issues/3389
I have tried to implement some functions for [rocketmq-client-go](https://github.com/apache/rocketmq-client-go), and I got a illgal json-style body for the response of broker with type [TopicStatsTable](https://github.com/apache/rocketmq/blob/master/common/src/main/java/org/apache/rocketmq/common/admin/TopicStatsTable.java). The string converted from the body looks like this: ``` {"offsetTable":{{"brokerName":"rocketmq-broker-a","queueId":2,"topic":"test"}:{"lastUpdateTimestamp":0,"maxOffset":0,"minOffset":0},{"brokerName":"rocketmq-broker-a","queueId":3,"topic":"test"}:{"lastUpdateTimestamp":0,"maxOffset":0,"minOffset":0},{"brokerName":"rocketmq-broker-a","queueId":0,"topic":"test"}:{"lastUpdateTimestamp":0,"maxOffset":0,"minOffset":0},{"brokerName":"rocketmq-broker-a","queueId":1,"topic":"test"}:{"lastUpdateTimestamp":0,"maxOffset":0,"minOffset":0},{"brokerName":"rocketmq-broker-a","queueId":6,"topic":"test"}:{"lastUpdateTimestamp":0,"maxOffset":0,"minOffset":0},{"brokerName":"rocketmq-broker-a","queueId":7,"topic":"test"}:{"lastUpdateTimestamp":0,"maxOffset":0,"minOffset":0},{"brokerName":"rocketmq-broker-a","queueId":4,"topic":"test"}:{"lastUpdateTimestamp":0,"maxOffset":0,"minOffset":0},{"brokerName":"rocketmq-broker-a","queueId":5,"topic":"test"}:{"lastUpdateTimestamp":0,"maxOffset":0,"minOffset":0}}} ``` And the json.Unmarshal method reports an error: ``` invalid character '{' looking for beginning of object key string ``` Simply, the problem is the serialized key of the response should be not an object but a string. And I got that the serialization library for the [rocketmq](https://github.com/apache/rocketmq) is [fastjson](https://github.com/alibaba/fastjson), and there is a reference of this problem in the issue [1.2.58,toJSONString(Object)生成了非标准JSON](https://github.com/alibaba/fastjson/issues/2526). Someone reports that the default settings for fastjson has changed after the version 1.2.36 released, and illegal json string can be serialized. However, the [RemotingSerializable.toJson](https://github.com/apache/rocketmq/blob/fb8bc64e2a2551e76da24cb6af0fb3e5f986f8b3/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/RemotingSerializable.java#L33) method is using the default settings. And I can give a simple bugfix: Previous: ```java public static String toJson(final Object obj, boolean prettyFormat) { return JSON.toJSONString(obj, prettyFormat); } ``` After: ``` public static String toJson(final Object obj, boolean prettyFormat) { if (prettyFormat) { return JSON.toJSONString(obj, SerializerFeature.WriteNonStringKeyAsString, SerializerFeature.PrettyFormat); } else { return JSON.toJSONString(obj, SerializerFeature.WriteNonStringKeyAsString); } } ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
