mirror of https://github.com/alibaba/fastjson2.git
				
				
				
			to #3789, toJavaObject IgnoreSetNullValue
This commit is contained in:
		
							parent
							
								
									3a23ee580c
								
							
						
					
					
						commit
						0e0c19f10a
					
				|  | @ -578,8 +578,10 @@ public class ObjectReaderAdapter<T> | |||
|                 FieldReader fieldReader = fieldReaders[i]; | ||||
|                 Object fieldValue = map.get(fieldReader.fieldName); | ||||
|                 if (fieldValue == null) { | ||||
|                     if ((features2 & JSONReader.Feature.IgnoreSetNullValue.mask) != 0 || !map.containsKey(fieldReader.fieldName)) { | ||||
|                         continue; | ||||
|                     } | ||||
|                 } | ||||
| 
 | ||||
|                 if (fieldReader.field != null && Modifier.isFinal(fieldReader.field.getModifiers())) { | ||||
|                     try { | ||||
|  | @ -592,7 +594,7 @@ public class ObjectReaderAdapter<T> | |||
|                     } | ||||
|                 } | ||||
| 
 | ||||
|                 if (fieldValue.getClass() == fieldReader.fieldType) { | ||||
|                 if (fieldValue == null || fieldValue.getClass() == fieldReader.fieldType) { | ||||
|                     fieldReader.accept(object, fieldValue); | ||||
|                 } else { | ||||
|                     if ((fieldReader instanceof FieldReaderList) | ||||
|  |  | |||
|  | @ -0,0 +1,35 @@ | |||
| package com.alibaba.fastjson2.issues_3700; | ||||
| 
 | ||||
| import com.alibaba.fastjson2.JSONException; | ||||
| import com.alibaba.fastjson2.JSONObject; | ||||
| import com.alibaba.fastjson2.JSONReader; | ||||
| import org.junit.jupiter.api.Test; | ||||
| 
 | ||||
| import static org.junit.jupiter.api.Assertions.*; | ||||
| 
 | ||||
| public class Issue3789 { | ||||
|     @Test | ||||
|     public void test() { | ||||
|         String name = "abc"; | ||||
| 
 | ||||
|         assertThrows(JSONException.class, | ||||
|                 () -> JSONObject.of("name", null).to(Bean.class)); | ||||
| 
 | ||||
|         assertNull(JSONObject.of("name", null).to(Bean.class, JSONReader.Feature.IgnoreSetNullValue).name); | ||||
|         assertNull(JSONObject.of().to(Bean.class).name); | ||||
| 
 | ||||
|         assertEquals(name, | ||||
|                 JSONObject.of("name", name).to(Bean.class).name); | ||||
|     } | ||||
| 
 | ||||
|     public static class Bean { | ||||
|         private String name; | ||||
| 
 | ||||
|         public void setName(String name) { | ||||
|             if (name == null) { | ||||
|                 throw new IllegalArgumentException(); | ||||
|             } | ||||
|             this.name = name; | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Loading…
	
		Reference in New Issue