zhishengzhang commented on code in PR #10283:
URL: https://github.com/apache/rocketmq/pull/10283#discussion_r3192825484
##########
remoting/src/test/java/org/apache/rocketmq/remoting/protocol/RemotingSerializableTest.java:
##########
@@ -121,6 +123,22 @@ public Map<Long, String> getMap() {
Assert.fail("Should not throw");
}
}
+ @Test
+ public void testDecodeUnquotedFieldNames() {
+ // 模拟 5.4.x 版本序列化的 consumerOffset 格式(数字 key 无引号)
+ String jsonWithUnquotedKeys =
"{\"offsetTable\":{\"TopicTest@gid-test\":{0:123,1:456}}}";
+ Map<String, Map<Integer, Long>> result =
RemotingSerializable.fromJson(jsonWithUnquotedKeys, Map.class);
+ assertNotNull(result);
+ Map offsetTable = (Map) result.get("offsetTable");
+ assertNotNull(offsetTable);
+
+ Map topicOffsets = (Map) offsetTable.get("TopicTest@gid-test");
+ assertNotNull(topicOffsets);
+
+ assertEquals(123L, ((Number) topicOffsets.get("0")).longValue());
Review Comment:
<img width="532" height="319" alt="截屏2026-05-06 11 29 14"
src="https://github.com/user-attachments/assets/9daa11e6-84ce-4715-85e9-fd6d16be46d3"
/>
The reason `get("0")` is used instead of `get(0)` is due to Gson's
deserialization behavior: when deserializing into a raw `Map` type,
Gson converts all keys to `String`, even if the original JSON key
is a numeric value like `0` or `1`.
--
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]