This commit is contained in:
Zhang Si
2020-05-24 22:41:28 +08:00
2 changed files with 46 additions and 0 deletions
@@ -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;
}
}