diff --git a/core/pom.xml b/core/pom.xml index db0d7e6665..e5a70457fe 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -225,6 +225,12 @@ commons-lang3 test + + org.apache.dubbo + dubbo + 3.2.5 + test + org.gitlab4j gitlab4j-api diff --git a/core/src/main/java/com/alibaba/fastjson2/JSONReaderJSONB.java b/core/src/main/java/com/alibaba/fastjson2/JSONReaderJSONB.java index 468f1e97e6..4ddfbdcf53 100644 --- a/core/src/main/java/com/alibaba/fastjson2/JSONReaderJSONB.java +++ b/core/src/main/java/com/alibaba/fastjson2/JSONReaderJSONB.java @@ -1076,7 +1076,7 @@ public List readArray() { offset += 3; value = int3; } else if (valueType == BC_INT32) { - int int32Value = UNSAFE.getInt(bytes, ARRAY_BYTE_BASE_OFFSET + offset); + int int32Value = UNSAFE.getInt(bytes, ARRAY_BYTE_BASE_OFFSET + offset + 1); offset += 5; value = BIG_ENDIAN ? int32Value : Integer.reverseBytes(int32Value); } else if (valueType == BC_REFERENCE) { diff --git a/core/src/test/java/com/alibaba/fastjson2/issues_1800/Issue1819.java b/core/src/test/java/com/alibaba/fastjson2/issues_1800/Issue1819.java new file mode 100644 index 0000000000..6f10309488 --- /dev/null +++ b/core/src/test/java/com/alibaba/fastjson2/issues_1800/Issue1819.java @@ -0,0 +1,45 @@ +package com.alibaba.fastjson2.issues_1800; + +import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.serialize.ObjectInput; +import org.apache.dubbo.common.serialize.ObjectOutput; +import org.apache.dubbo.common.serialize.Serialization; +import org.apache.dubbo.rpc.model.FrameworkModel; +import org.junit.jupiter.api.Test; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class Issue1819 { + @Test + public void testWriteReadMap() throws Exception { + FrameworkModel frameworkModel = new FrameworkModel(); + Serialization serialization = frameworkModel.getExtensionLoader(Serialization.class).getExtension("fastjson2"); + URL url = URL.valueOf("").setScopeModel(frameworkModel); + + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + ObjectOutput objectOutput = serialization.serialize(url, outputStream); + Map map = new HashMap<>(); + List workBysOrigin = new ArrayList<>(); + workBysOrigin.add(120731003); + workBysOrigin.add(140707005); + map.put("work_by", workBysOrigin); + objectOutput.writeObject(map); + objectOutput.flushBuffer(); + + byte[] bytes = outputStream.toByteArray(); + ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes); + ObjectInput objectInput = serialization.deserialize(url, inputStream); + map = objectInput.readObject(Map.class); + List workBys = (List) map.get("work_by"); + for (int i = 0; i < workBys.size(); i++) { + assertEquals(workBysOrigin.get(i), workBys.get(i)); + } + } +}