Skip to content

Commit db4221c

Browse files
committed
2.0.61.android8
1 parent f4790b9 commit db4221c

6 files changed

Lines changed: 56 additions & 5 deletions

File tree

benchmark/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.alibaba.fastjson2</groupId>
88
<artifactId>fastjson2-parent</artifactId>
9-
<version>2.0.60.android8</version>
9+
<version>2.0.61.android8</version>
1010
<relativePath>../pom.xml</relativePath>
1111
</parent>
1212

core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.alibaba.fastjson2</groupId>
88
<artifactId>fastjson2-parent</artifactId>
9-
<version>2.0.60.android8</version>
9+
<version>2.0.61.android8</version>
1010
<relativePath>../pom.xml</relativePath>
1111
</parent>
1212

core/src/main/java/com/alibaba/fastjson2/writer/ObjectWriterAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ public void writeWithFilter(JSONWriter jsonWriter, Object object, Object fieldNa
405405
return;
406406
}
407407

408-
if (jsonWriter.isWriteTypeInfo(object, fieldType, features)) {
408+
if (jsonWriter.isWriteTypeInfo(object, fieldType, this.features | features)) {
409409
if (jsonWriter.jsonb) {
410410
writeClassInfo(jsonWriter);
411411
jsonWriter.startObject();

core/src/main/java/com/alibaba/fastjson2/writer/ObjectWriterBigInteger.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ public void writeJSONB(JSONWriter jsonWriter, Object object, Object fieldName, T
2424
jsonWriter.writeBigInt((BigInteger) object, features);
2525
}
2626

27+
@Override
28+
public void writeArrayMappingJSONB(JSONWriter jsonWriter, Object object, Object fieldName, Type fieldType, long features) {
29+
if (object == null) {
30+
jsonWriter.writeNumberNull();
31+
return;
32+
}
33+
jsonWriter.writeBigInt((BigInteger) object, features);
34+
}
35+
2736
@Override
2837
public void write(JSONWriter jsonWriter, Object object, Object fieldName, Type fieldType, long features) {
2938
if (object == null) {

core/src/test/java/com/alibaba/fastjson2/features/WriteClassNameWithFilterTest.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
import com.alibaba.fastjson2.JSON;
44
import com.alibaba.fastjson2.JSONWriter;
5+
import com.alibaba.fastjson2.annotation.JSONType;
56
import com.alibaba.fastjson2.filter.ValueFilter;
67
import org.junit.jupiter.api.Test;
78

89
import static org.junit.jupiter.api.Assertions.assertEquals;
10+
import static org.junit.jupiter.api.Assertions.assertTrue;
911

1012
public class WriteClassNameWithFilterTest {
1113
@Test
@@ -18,7 +20,48 @@ public void test() {
1820
assertEquals("{\"@type\":\"com.alibaba.fastjson2.features.WriteClassNameWithFilterTest$Bean\",\"id\":101}", str);
1921
}
2022

23+
@Test
24+
public void testAnnotationSerializeFeaturesWithFilter() {
25+
Circle circle = new Circle();
26+
circle.setType("circle");
27+
circle.setRadius(10);
28+
29+
ValueFilter filter = (Object object, String name, Object value) -> value;
30+
31+
String str = JSON.toJSONString(circle, filter);
32+
33+
assertTrue(str.contains("\"type\":\"circle\""), "Should contain type:circle, actual: " + str);
34+
assertTrue(str.contains("\"radius\":10"), "Should contain radius:10, actual: " + str);
35+
}
36+
2137
public static class Bean {
2238
public Integer id;
2339
}
40+
41+
@JSONType(typeKey = "type")
42+
public static class Shape {
43+
private String type;
44+
45+
public String getType() {
46+
return this.type;
47+
}
48+
49+
public void setType(String type) {
50+
this.type = type;
51+
}
52+
}
53+
54+
@JSONType(typeKey = "type", typeName = "circle", serializeFeatures = JSONWriter.Feature.WriteClassName)
55+
public static class Circle
56+
extends Shape {
57+
private int radius;
58+
59+
public int getRadius() {
60+
return radius;
61+
}
62+
63+
public void setRadius(int radius) {
64+
this.radius = radius;
65+
}
66+
}
2467
}

pom.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.alibaba.fastjson2</groupId>
88
<artifactId>fastjson2-parent</artifactId>
9-
<version>2.0.60.android8</version>
9+
<version>2.0.61.android8</version>
1010
<name>${project.artifactId}</name>
1111
<description>Fastjson is a JSON processor (JSON parser + JSON generator) written in Java</description>
1212
<packaging>pom</packaging>
@@ -57,7 +57,6 @@
5757

5858
<modules>
5959
<module>benchmark</module>
60-
<module>codegen-test</module>
6160
<module>core</module>
6261
</modules>
6362

0 commit comments

Comments
 (0)