/
Issue3217.java
98 lines (68 loc) · 2.35 KB
/
Issue3217.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package com.alibaba.json.bvt.issue_3300;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.AfterFilter;
import junit.framework.TestCase;
import java.util.ArrayList;
import java.util.List;
public class Issue3217 extends TestCase {
public void test_for_issue() throws Exception {
RefAfterFilterTest refAfterFilterTest = new RefAfterFilterTest();
List<Item> items = new ArrayList<Item>(2);
Category category = new Category("category");
items.add(new Item("item1",category));
items.add(new Item("item2",category));
System.out.println(JSON.toJSONString(items,refAfterFilterTest));
}
public static class RefAfterFilterTest extends AfterFilter {
private Category category = new Category("afterFilterCategory");
@Override
public void writeAfter(Object object) {
if (object instanceof Item) {
this.writeKeyValue("afterFilterCategory", category);
/*多加一个属性报错,原因是category是object也触发了writeAfter,当前线程变量serializer被设置为null了serializerLocal.set(null);
*这两个write换个顺序就不会报错
*/
this.writeKeyValue("afterFilterTwo", "two");
}
}
}
public static class Category {
private String name;
public Category(String name){
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
public static class Item {
private String name;
private Category category;
private String barcode;
public Item(String name,Category category){
this.name = name;
this.category = category;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Category getCategory() {
return category;
}
public void setCategory(Category category) {
this.category = category;
}
public String getBarcode() {
return barcode;
}
public void setBarcode(String barcode) {
this.barcode = barcode;
}
}
}