File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -240,7 +240,7 @@ private Object decode_(JsonIterator iter) throws Exception {
240240 setExtra (obj , extra );
241241 for (Binding field : desc .fields ) {
242242 Object val = temp [field .idx ];
243- if (val != NOT_SET ) {
243+ if (val != NOT_SET && field . fromNames . length > 0 ) {
244244 field .field .set (obj , val );
245245 }
246246 }
Original file line number Diff line number Diff line change 11package com .jsoniter ;
22
3+ import com .jsoniter .annotation .JsonCreator ;
34import com .jsoniter .annotation .JsonIgnore ;
5+ import com .jsoniter .annotation .JsonProperty ;
6+ import com .jsoniter .spi .DecodingMode ;
47import junit .framework .TestCase ;
8+ import org .junit .Test ;
59
10+ import java .awt .event .ActionEvent ;
11+ import java .awt .event .ActionListener ;
612import java .io .IOException ;
713import java .io .Serializable ;
814
@@ -29,4 +35,32 @@ public void test_ignore_no_constructor_field() throws IOException {
2935 TestObject2 obj = iter .read (TestObject2 .class );
3036 assertNull (obj .field2 );
3137 }
38+
39+ public static class TestObject3 {
40+ String field1 ;
41+ @ JsonIgnore
42+ ActionListener fieldXXX ;
43+
44+ @ JsonCreator
45+ public TestObject3 (@ JsonProperty ("field2" ) final String field ) {
46+ field1 = null ;
47+ fieldXXX = new ActionListener () {
48+ @ Override
49+ public void actionPerformed (ActionEvent e ) {
50+ System .out .println ("field2 is " + field );
51+ }
52+ };
53+ }
54+
55+ @ Override
56+ public String toString () {
57+ return "field1=" + field1 + ", field2=" + fieldXXX ;
58+ }
59+ }
60+
61+ public void test_json_ignore_with_creator () throws IOException {
62+ JsonIterator iter = JsonIterator .parse ("{\" field2\" : \" test\" }" );
63+ TestObject3 t = iter .read (TestObject3 .class );
64+ assertNotNull (t .fieldXXX );
65+ }
3266}
You can’t perform that action at this time.
0 commit comments