Commit 84835dd3 authored by 高铁's avatar 高铁
Browse files

bug fixed for set list

parent b1838616
Showing with 37 additions and 4 deletions
+37 -4
......@@ -2,8 +2,10 @@ package com.alibaba.fastjson.parser.deserializer;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.parser.DefaultJSONParser;
import com.alibaba.fastjson.parser.ParserConfig;
import com.alibaba.fastjson.serializer.BeanContext;
import com.alibaba.fastjson.util.FieldInfo;
import com.alibaba.fastjson.util.TypeUtils;
import java.lang.reflect.*;
import java.util.Collection;
......@@ -221,12 +223,27 @@ public abstract class FieldDeserializer {
/**
* kotlin代理类property的get方法会抛未初始化异常,用set方法直接赋值
*/
private static void degradeValueAssignment(Field field,Method getMethod, Object object, Object value) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
private static boolean degradeValueAssignment(
Field field,
Method getMethod,
Object object,
Object value
) throws InvocationTargetException, IllegalAccessException {
if (setFieldValue(field, object, value)) {
return;
return true;
}
Method setMethod = object.getClass().getDeclaredMethod("set" + getMethod.getName().substring(3), getMethod.getReturnType());
setMethod.invoke(object, value);
try {
Method setMethod = object
.getClass()
.getDeclaredMethod("set" + getMethod.getName().substring(3), getMethod.getReturnType());
setMethod.invoke(object, value);
return true;
} catch (InvocationTargetException ignored) {
} catch (NoSuchMethodException ignored) {
} catch (IllegalAccessException ignored) {
}
return false;
}
private static boolean setFieldValue(Field field, Object object, Object value) throws IllegalAccessException {
......
package com.alibaba.json.bvt.parser.deser.list;
import com.alibaba.fastjson.JSON;
import junit.framework.TestCase;
public class ListFieldTest extends TestCase {
public void test_for_list() throws Exception {
JSON.parseObject("{'data':['a','b']}", TestPojo.class);
}
public static class TestPojo{
public java.util.List<String> getData(){
return null;
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment