Skip to content

Commit

Permalink
bug fixed for getOnly toJavaObject
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Dec 29, 2016
1 parent e1c79e2 commit 2756655
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -815,17 +815,11 @@ public Object createInstance(Map<String, Object> map, ParserConfig config) //
continue;
}

Method method = fieldDeser.fieldInfo.method;
if (method != null) {
Type paramType = method.getGenericParameterTypes()[0];
value = TypeUtils.cast(value, paramType, config);
method.invoke(object, new Object[] { value });
} else {
Field field = fieldDeser.fieldInfo.field;
Type paramType = fieldDeser.fieldInfo.fieldType;
value = TypeUtils.cast(value, paramType, config);
field.set(object, value);
}
final FieldInfo fieldInfo = fieldDeser.fieldInfo;
Type paramType = fieldInfo.fieldType;
value = TypeUtils.cast(value, paramType, config);

fieldDeser.setValue(object, value);
}

if (beanInfo.buildMethod != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.alibaba.json.bvt.bug;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import junit.framework.Test;
import junit.framework.TestCase;

import java.util.ArrayList;
import java.util.List;

/**
* Created by wenshao on 29/12/2016.
*/
public class Issue_for_oschina_3087749_2215732 extends TestCase {
public void test_for_issue() throws Exception {
String json = "{\"datas\":[\"a\",\"b\"]}";
JSONObject o = JSON.parseObject(json);
o.toJavaObject(JsonBean.class);
}

public static class JsonBean {
private List<String> datas = new ArrayList<String>();
public List<String> getDatas() {
return datas;
}
}
}

0 comments on commit 2756655

Please sign in to comment.