File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed
main/java/com/alibaba/fastjson2/reader
test/java/com/alibaba/fastjson2/issues_2300 Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -1637,7 +1637,7 @@ boolean record = BeanUtils.isRecord(objectClass);
16371637 if (!record ) {
16381638 BeanUtils .declaredFields (objectClass , field -> {
16391639 fieldInfo .init ();
1640- fieldInfo .ignore = (field .getModifiers () & Modifier .PUBLIC ) == 0 ;
1640+ fieldInfo .ignore = (field .getModifiers () & Modifier .PUBLIC ) == 0 && (( beanFeatures & JSONReader . Feature . FieldBased . mask ) == 0 ) ;
16411641 fieldInfo .features |= beanFeatures ;
16421642 fieldInfo .format = beanFormat ;
16431643
Original file line number Diff line number Diff line change 1+ package com .alibaba .fastjson2 .issues_2300 ;
2+
3+ import com .alibaba .fastjson2 .JSON ;
4+ import com .alibaba .fastjson2 .JSONReader ;
5+ import com .alibaba .fastjson2 .annotation .JSONType ;
6+ import org .junit .jupiter .api .Test ;
7+
8+ import static org .junit .jupiter .api .Assertions .assertEquals ;
9+
10+ public class Issue2371 {
11+ @ JSONType (deserializeFeatures = JSONReader .Feature .FieldBased )
12+ private static class Bean {
13+ private String testField ;
14+
15+ public String getTestField () {
16+ return testField ;
17+ }
18+ }
19+
20+ @ Test
21+ public void test () {
22+ Bean test = JSON .parseObject ("{\" testField\" : \" My Test\" }" , Bean .class );
23+ assertEquals ("My Test" , test .getTestField ());
24+ }
25+ }
You can’t perform that action at this time.
0 commit comments