diff --git a/core/src/main/java/com/alibaba/fastjson2/filter/ContextAutoTypeBeforeHandler.java b/core/src/main/java/com/alibaba/fastjson2/filter/ContextAutoTypeBeforeHandler.java index e7b18406af..6b50f01409 100644 --- a/core/src/main/java/com/alibaba/fastjson2/filter/ContextAutoTypeBeforeHandler.java +++ b/core/src/main/java/com/alibaba/fastjson2/filter/ContextAutoTypeBeforeHandler.java @@ -46,6 +46,9 @@ public ContextAutoTypeBeforeHandler(String... acceptNames) { long hashCode = MAGIC_HASH_CODE; for (int j = 0; j < name.length(); ++j) { char ch = name.charAt(j); + if (ch == '$') { + ch = '.'; + } hashCode ^= ch; hashCode *= MAGIC_PRIME; } diff --git a/core/src/test/java/com/alibaba/fastjson2/issues/Issue750.java b/core/src/test/java/com/alibaba/fastjson2/issues/Issue750.java new file mode 100644 index 0000000000..f9d0c10280 --- /dev/null +++ b/core/src/test/java/com/alibaba/fastjson2/issues/Issue750.java @@ -0,0 +1,24 @@ +package com.alibaba.fastjson2.issues; + +import com.alibaba.fastjson2.JSONB; +import com.alibaba.fastjson2.JSONReader; +import com.alibaba.fastjson2.JSONWriter; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class Issue750 { + @Test + public void test() { + Bean bean = new Bean(); + bean.id = 123; + + byte[] bytes = JSONB.toBytes(bean, JSONWriter.Feature.WriteClassName); + Bean bean1 = (Bean) JSONB.parseObject(bytes, Object.class, JSONReader.autoTypeFilter(Bean.class)); + assertEquals(bean.id, bean1.id); + } + + public static class Bean { + public int id; + } +}