rocketmq icon indicating copy to clipboard operation
rocketmq copied to clipboard

RocketMQ is producing non-standard-compliant JSON

Open lizhanhui opened this issue 5 years ago • 1 comments

RocketMQ uses fastjson to serialize object to JSON text. Unfortunately, with the default configuration, the FastJson library does not respect the JSON standard as expected, which imposes an enormous obstacle for other languages to talk to RocketMQ.

For example,

        Map<Integer, String> map = new HashMap<Integer, String>();
        map.put(1, "abc");
        map.put(2, "def");
        System.out.println(RemotingSerializable.toJson(map, false));

generates

{1:"abc",2:"def"}

which does not comply with the JSON standard and may be validated in JSON Lint.

non-standard-compliant JSON can not be parsed by many JSON libraries, say JsonCpp, RapidJson, etc. It's mandatory to fix this.

lizhanhui avatar Oct 07 '19 10:10 lizhanhui

Same issue in OffsetSerializeWrapper,

private ConcurrentMap<MessageQueue, AtomicLong> offsetTable = new ConcurrentHashMap<MessageQueue, AtomicLong>();

the key of offsetTable is MessageQueue object, but only string is accepted as object key in JSON standard.

ifplusor avatar Oct 08 '19 12:10 ifplusor

https://github.com/alibaba/fastjson/issues/2078

xiaoyifang avatar Oct 21 '22 07:10 xiaoyifang