com.github.siwenyan.query.JsonpathQuery Maven / Gradle / Ivy
package com.github.siwenyan.query;
import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.JsonPath;
import org.apache.log4j.Logger;
/**
* QueryBase implementation to support jsonpath query
*/
public class JsonpathQuery extends QueryBase {
public static final Logger log = Logger.getLogger(JsonpathQuery.class.getName());
private String body = null;
private DocumentContext dc = null;
public JsonpathQuery(String body) {
this.body = body;
this.dc = JsonPath.parse(body);
log.warn(body);
}
@Override
public Object query(String jsonpath) {
try {
return this.dc.read(jsonpath);
} catch (Exception e) {
return null;
}
}
@Override
public String toString() {
return this.body;
}
}