mirror of
https://github.com/alibaba/fastjson.git
synced 2026-10-27 04:10:07 +08:00
improve odps support
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -150,6 +150,8 @@ public class SerializeConfig extends IdentityHashMap<Type, ObjectSerializer> {
|
||||
|
||||
try {
|
||||
asmFactory = new ASMSerializerFactory();
|
||||
} catch (NoClassDefFoundError eror) {
|
||||
asm = false;
|
||||
} catch (ExceptionInInitializerError error) {
|
||||
asm = false;
|
||||
}
|
||||
|
||||
+1
-1
@@ -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;
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user