diff --git a/src/main/java/com/alibaba/fastjson/parser/ParserConfig.java b/src/main/java/com/alibaba/fastjson/parser/ParserConfig.java index d5775d7d0..006a37bfd 100755 --- a/src/main/java/com/alibaba/fastjson/parser/ParserConfig.java +++ b/src/main/java/com/alibaba/fastjson/parser/ParserConfig.java @@ -36,6 +36,7 @@ import java.net.InetSocketAddress; import java.net.URI; import java.net.URL; import java.nio.charset.Charset; +import java.security.AccessControlException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; @@ -171,6 +172,10 @@ public class ParserConfig { } else { asmFactory = new ASMDeserializerFactory(parentClassLoader); } + } catch (ExceptionInInitializerError error) { + // skip + } catch (AccessControlException error) { + // skip } catch (NoClassDefFoundError error) { // skip } diff --git a/src/main/java/com/alibaba/fastjson/serializer/SerializeConfig.java b/src/main/java/com/alibaba/fastjson/serializer/SerializeConfig.java index f91ec00c8..d85d30f90 100755 --- a/src/main/java/com/alibaba/fastjson/serializer/SerializeConfig.java +++ b/src/main/java/com/alibaba/fastjson/serializer/SerializeConfig.java @@ -150,6 +150,8 @@ public class SerializeConfig extends IdentityHashMap { try { asmFactory = new ASMSerializerFactory(); + } catch (NoClassDefFoundError eror) { + asm = false; } catch (ExceptionInInitializerError error) { asm = false; } diff --git a/src/main/java/com/alibaba/fastjson/support/odps/CodecCheck.java b/src/main/java/com/alibaba/fastjson/support/odps/udf/CodecCheck.java similarity index 94% rename from src/main/java/com/alibaba/fastjson/support/odps/CodecCheck.java rename to src/main/java/com/alibaba/fastjson/support/odps/udf/CodecCheck.java index 6331b88aa..5d9b4b7b0 100644 --- a/src/main/java/com/alibaba/fastjson/support/odps/CodecCheck.java +++ b/src/main/java/com/alibaba/fastjson/support/odps/udf/CodecCheck.java @@ -1,4 +1,4 @@ -package com.alibaba.fastjson.support.odps; +package com.alibaba.fastjson.support.odps.udf; import com.alibaba.fastjson.JSON; import com.aliyun.odps.udf.UDF; diff --git a/src/main/java/com/alibaba/fastjson/support/odps/udf/GetJSONObject.java b/src/main/java/com/alibaba/fastjson/support/odps/udf/GetJSONObject.java new file mode 100644 index 000000000..7a301c7f1 --- /dev/null +++ b/src/main/java/com/alibaba/fastjson/support/odps/udf/GetJSONObject.java @@ -0,0 +1,19 @@ +package com.alibaba.fastjson.support.odps.udf; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONPath; +import com.alibaba.fastjson.serializer.SerializeConfig; +import com.aliyun.odps.udf.UDF; + +public class GetJSONObject extends UDF { + public GetJSONObject() { + // SerializeConfig.getGlobalInstance().setAsmEnable(false); + } + + public String evaluate(String jsonString, String path) throws Exception { + Object json = JSON.parse(jsonString); + JSONPath json_path = new JSONPath(path); + Object result = json_path.eval(json); + return JSON.toJSONString(result); + } +} diff --git a/src/test/java/com/alibaba/json/bvt/odps/GetJSONObjectTest.java b/src/test/java/com/alibaba/json/bvt/odps/GetJSONObjectTest.java new file mode 100644 index 000000000..0dddd3bd1 --- /dev/null +++ b/src/test/java/com/alibaba/json/bvt/odps/GetJSONObjectTest.java @@ -0,0 +1,14 @@ +package com.alibaba.json.bvt.odps; + +import junit.framework.TestCase; + +import com.alibaba.fastjson.support.odps.udf.GetJSONObject; + + +public class GetJSONObjectTest extends TestCase { + public void test_udf() throws Exception { + GetJSONObject udf = new GetJSONObject(); + String result = udf.evaluate("{\"id\":123,\"name\":\"wenshao\"}", "$"); + System.out.println(result); + } +} diff --git a/src/test/java/com/alibaba/json/bvt/path/JSONPath_list.java b/src/test/java/com/alibaba/json/bvt/path/JSONPath_list.java index d18d867c4..db8f33f87 100644 --- a/src/test/java/com/alibaba/json/bvt/path/JSONPath_list.java +++ b/src/test/java/com/alibaba/json/bvt/path/JSONPath_list.java @@ -18,6 +18,7 @@ public class JSONPath_list extends TestCase { List list = new ArrayList(); list.add(map); Assert.assertSame(map.get("val"), new JSONPath("$[0].val").eval(list)); + Assert.assertSame(map.get("val"), new JSONPath("$[-1].val").eval(list)); } }