File tree Expand file tree Collapse file tree 3 files changed +19
-8
lines changed
main/java/com/jsoniter/spi Expand file tree Collapse file tree 3 files changed +19
-8
lines changed Original file line number Diff line number Diff line change @@ -128,6 +128,9 @@ private static void decodingDeduplicate(ClassDescriptor desc) {
128128 ArrayList <Binding > iteratingSetters = new ArrayList <Binding >(desc .setters );
129129 Collections .reverse (iteratingSetters );
130130 for (Binding setter : iteratingSetters ) {
131+ if (setter .fromNames .length == 0 ) {
132+ continue ;
133+ }
131134 Binding existing = byFieldName .get (setter .name );
132135 if (existing != null ) {
133136 existing .fromNames = new String [0 ];
@@ -168,6 +171,9 @@ private static void encodingDeduplicate(ClassDescriptor desc) {
168171 byFieldName .put (field .name , field );
169172 }
170173 for (Binding getter : new ArrayList <Binding >(desc .getters )) {
174+ if (getter .toNames .length == 0 ) {
175+ continue ;
176+ }
171177 Binding existing = byFieldName .get (getter .name );
172178 if (existing != null ) {
173179 existing .toNames = new String [0 ];
Original file line number Diff line number Diff line change @@ -420,8 +420,15 @@ private void updateBindings(ClassDescriptor desc) {
420420 if (annotated && binding .field != null ) {
421421 if (desc .setters != null ) {
422422 for (Binding setter : desc .setters ) {
423- if (binding .name .equals (setter .name )) {
424- throw new JsonException ("annotation should be marked on getter/setter for field: " + binding .name );
423+ if (binding .field .getName ().equals (setter .name )) {
424+ setter .fromNames = new String [0 ];
425+ setter .toNames = new String [0 ];
426+ }
427+ }
428+ for (Binding getter : desc .getters ) {
429+ if (binding .field .getName ().equals (getter .name )) {
430+ getter .fromNames = new String [0 ];
431+ getter .toNames = new String [0 ];
425432 }
426433 }
427434 }
Original file line number Diff line number Diff line change @@ -178,12 +178,10 @@ public void setField(int field) {
178178 }
179179 }
180180
181- public void test_should_throw_exception_when_json_property_on_field_when_getter_and_setter_present () {
181+ public void test_field_and_getter_setter () {
182182 String input = "{\" hello\" :100}" ;
183- try {
184- JsonIterator .deserialize (input , TestObject11 .class );
185- fail ();
186- } catch (JsonException e ) {
187- }
183+ TestObject11 obj = JsonIterator .deserialize (input , TestObject11 .class );
184+ assertEquals (100 , obj .field );
188185 }
186+
189187}
You can’t perform that action at this time.
0 commit comments