Skip to content

Commit

Permalink
fix : nested class autoTypeFilter not work, for issue #750
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Sep 11, 2022
1 parent 446f6ce commit 0d0621b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
24 changes: 24 additions & 0 deletions core/src/test/java/com/alibaba/fastjson2/issues/Issue750.java
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 0d0621b

Please sign in to comment.