mirror of
https://github.com/alibaba/fastjson.git
synced 2026-10-22 17:38:29 +08:00
Merge branch 'master' of https://github.com/alibaba/fastjson
This commit is contained in:
@@ -3844,6 +3844,10 @@ public class JSONPath implements JSONAware {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (value != null && value.getClass() != fieldDeserializer.fieldInfo.fieldClass) {
|
||||
value = TypeUtils.cast(value, fieldDeserializer.fieldInfo.fieldType, parserConfig);
|
||||
}
|
||||
|
||||
fieldDeserializer.setValue(parent, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.alibaba.json.bvt.path;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.JSONPath;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class JSONPath_set_test7 extends TestCase {
|
||||
public void test_jsonpath_1() throws Exception {
|
||||
JSONObject aa= new JSONObject();
|
||||
aa.put("val", "false");
|
||||
JSONPath path = JSONPath.compile("$.val");
|
||||
|
||||
path.set(aa, true);
|
||||
assertEquals(true, aa.getBoolean("val").booleanValue());
|
||||
|
||||
path.set(aa, false);
|
||||
assertEquals(false, aa.getBoolean("val").booleanValue());
|
||||
}
|
||||
|
||||
public void test_jsonpath_2() throws Exception {
|
||||
VO aa = new VO();
|
||||
JSONPath path = JSONPath.compile("$.val");
|
||||
|
||||
path.set(aa, true);
|
||||
assertEquals(true, aa.val);
|
||||
|
||||
path.set(aa, false);
|
||||
assertEquals(false, aa.val);
|
||||
|
||||
path.set(aa, "true");
|
||||
assertEquals(true, aa.val);
|
||||
|
||||
path.set(aa, "false");
|
||||
assertEquals(false, aa.val);
|
||||
}
|
||||
|
||||
|
||||
public static class VO {
|
||||
public boolean val;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user