本文整理汇总了Java中net.thisptr.jackson.jq.JsonQuery类的典型用法代码示例。如果您正苦于以下问题:Java JsonQuery类的具体用法?Java JsonQuery怎么用?Java JsonQuery使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JsonQuery类属于net.thisptr.jackson.jq包,在下文中一共展示了JsonQuery类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initialize
import net.thisptr.jackson.jq.JsonQuery; //导入依赖的package包/类
private StructObjectInspector initialize(final ObjectInspector jsonArg, final ObjectInspector jqArg, final List<ObjectInspector> nameAndTypeArgs) throws UDFArgumentException {
this.in = Arguments.asString(jsonArg, "JSON");
try {
this.jq = JsonQuery.compile(Arguments.asConstantNonNullString(jqArg, "JQ"));
} catch (final JsonQueryException e) {
throw new UDFArgumentException("JQ is invalid: " + e.getMessage());
}
this.marshaller = ResultObjectMarshallers.create(Arguments.asConstantNonNullStrings(nameAndTypeArgs, "TYPE or NAME:TYPE"));
this.scope = new Scope();
this.mapper = new ObjectMapper(new JsonFactory().enable(Feature.ALLOW_UNQUOTED_CONTROL_CHARS));
return marshaller.objectInspector();
}
示例2: start
import net.thisptr.jackson.jq.JsonQuery; //导入依赖的package包/类
@Override
public void start(Workflow workflow, Task task, WorkflowExecutor executor) throws Exception {
Map<String, Object> taskInput = task.getInputData();
Map<String, Object> taskOutput = task.getOutputData();
String queryExpression = (String) taskInput.get(QUERY_EXPRESSION_PARAMETER);
if(queryExpression == null) {
task.setReasonForIncompletion("Missing '" + QUERY_EXPRESSION_PARAMETER + "' in input parameters");
task.setStatus(Task.Status.FAILED);
return;
}
try {
JsonNode input = om.valueToTree(taskInput);
JsonQuery query = queryCache.get(queryExpression);
List<JsonNode> result = query.apply(input);
task.setStatus(Task.Status.COMPLETED);
if (result == null) {
taskOutput.put("result", null);
taskOutput.put("resultList", null);
} else if (result.isEmpty()) {
taskOutput.put("result", null);
taskOutput.put("resultList", result);
} else {
taskOutput.put("result", result.get(0));
taskOutput.put("resultList", result);
}
} catch(Exception e) {
logger.error(e.getMessage(), e);
task.setStatus(Task.Status.FAILED);
task.setReasonForIncompletion(e.getMessage());
taskOutput.put("error", e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
}
}
示例3: createQueryCache
import net.thisptr.jackson.jq.JsonQuery; //导入依赖的package包/类
private LoadingCache<String, JsonQuery> createQueryCache() {
CacheLoader<String, JsonQuery> loader = new CacheLoader<String, JsonQuery>() {
@Override
public JsonQuery load(@Nonnull String query) throws JsonQueryException {
return JsonQuery.compile(query);
}
};
return CacheBuilder.newBuilder().expireAfterWrite(1, TimeUnit.HOURS).maximumSize(1000).build(loader);
}