本文整理汇总了Java中org.codehaus.jackson.JsonNode类的典型用法代码示例。如果您正苦于以下问题:Java JsonNode类的具体用法?Java JsonNode怎么用?Java JsonNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JsonNode类属于org.codehaus.jackson包,在下文中一共展示了JsonNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deserialize
import org.codehaus.jackson.JsonNode; //导入依赖的package包/类
@Override
public Directive deserialize(JsonParser jp, DeserializationContext ctx)
throws IOException {
ObjectReader reader = ObjectMapperUtil.instance().getObjectReader();
ObjectNode obj = (ObjectNode) reader.readTree(jp);
Iterator<Map.Entry<String, JsonNode>> elementsIterator = obj.getFields();
String rawMessage = obj.toString();
DialogRequestIdHeader header = null;
JsonNode payloadNode = null;
ObjectReader headerReader =
ObjectMapperUtil.instance().getObjectReader(DialogRequestIdHeader.class);
while (elementsIterator.hasNext()) {
Map.Entry<String, JsonNode> element = elementsIterator.next();
if (element.getKey().equals("header")) {
header = headerReader.readValue(element.getValue());
}
if (element.getKey().equals("payload")) {
payloadNode = element.getValue();
}
}
if (header == null) {
throw ctx.mappingException("Missing header");
}
if (payloadNode == null) {
throw ctx.mappingException("Missing payload");
}
return createDirective(header, payloadNode, rawMessage);
}
示例2: search
import org.codehaus.jackson.JsonNode; //导入依赖的package包/类
public String search(String query) {
try {
String url = "?text=" + Utility.urlEncode(query) + "&confidence=" + confidence;
HttpGet httpGet = new HttpGet(URL + url);
httpGet.addHeader("Accept", "application/json");
HttpResponse response = client.execute(httpGet);
// Error Scenario
if(response.getStatusLine().getStatusCode() >= 400) {
logger.error("Spotlight Service could not answer due to: " + response.getStatusLine());
return null;
}
else {
String entities = EntityUtils.toString(response.getEntity());
JsonNode entity = new ObjectMapper().readTree(entities).get("Resources").get(0);
return entity.get("@URI").getTextValue();
}
}
catch (Exception e) {
e.printStackTrace();
}
return null;
}
示例3: deserialize
import org.codehaus.jackson.JsonNode; //导入依赖的package包/类
@Override
public Window deserialize(JsonParser jp, DeserializationContext dc) throws IOException, JsonProcessingException {
JsonNode node = jp.getCodec().readTree(jp);
Double value = node.get("value").asDouble();
Window window = new Window(value);
if (node.has("bounds")) {
long lowerBound = node.get("bounds").get(0).asLong();
long upperBound = node.get("bounds").get(1).asLong();
window.withLowerBound(lowerBound).withUpperBound(upperBound);
}
return window;
}
示例4: getCriteria
import org.codehaus.jackson.JsonNode; //导入依赖的package包/类
public static Criteria getCriteria(ObjectNode rudeCriteria) throws Exception {
Criteria criteria = new Criteria();
if (rudeCriteria.has("criterions")) {
ArrayNode criterions = (ArrayNode) rudeCriteria.get("criterions");
if (criterions != null) {
for (Iterator<JsonNode> it = criterions.iterator(); it.hasNext();) {
criteria.addCriterion(parseCriterion((ObjectNode) it.next()));
}
}
}
if (rudeCriteria.has("orders")) {
ArrayNode orders = (ArrayNode) rudeCriteria.get("orders");
if (orders != null) {
for (Iterator<JsonNode> it = orders.iterator(); it.hasNext();) {
ObjectNode rudeCriterion = (ObjectNode) it.next();
Order order = new Order(JsonUtils.getString(rudeCriterion, "property"), JsonUtils.getBoolean(rudeCriterion, "desc"));
criteria.addOrder(order);
}
}
}
return criteria;
}
示例5: getExecLog
import org.codehaus.jackson.JsonNode; //导入依赖的package包/类
public String getExecLog(int execId, String jobName, String offset, String length)
throws Exception {
Map<String, String> paramsMap = new HashMap<>();
// TODO try with session id, if it expired, re-login
paramsMap.put("ajax", "fetchExecJobLogs");
paramsMap.put("execid", String.valueOf(execId));
paramsMap.put("jobId", jobName);
paramsMap.put("offset", offset);
paramsMap.put("length", length);
String url = AZKABAN_URL + "/executor";
String response = sendRequest(url, paramsMap, "get");
// retrieve from json
JsonNode obj = jsonReader.readTree(response);
String execLog = obj.get("data").asText();
return execLog;
}
示例6: parseJsonHelper
import org.codehaus.jackson.JsonNode; //导入依赖的package包/类
/**
* Recursively process the execution info to get {@AzkabanJobExecRecord}
* @param allJobs JsonNode in "nodes" field
* @param flowExecId
* @param flowPath Format : project_name:first_level_flow/sub_flow/sub_flow
* @return
*/
private List<AzkabanJobExecRecord> parseJsonHelper(JsonNode allJobs, long flowExecId, String flowPath) {
List<AzkabanJobExecRecord> results = new ArrayList<>();
for (JsonNode oneJob : allJobs) {
if (oneJob.has("nodes")) { // is a subflow
String subFlowName = oneJob.get("id").asText();
flowPath += "/" + subFlowName;
results.addAll(parseJsonHelper(oneJob.get("nodes"), flowExecId, flowPath));
} else {
String jobName = oneJob.get("id").asText();
long startTime = oneJob.get("startTime").asLong();
long endTime = oneJob.get("endTime").asLong();
String status = oneJob.get("status").asText();
AzkabanJobExecRecord azkabanJobExecRecord =
new AzkabanJobExecRecord(appId, jobName, flowExecId, (int) (startTime / 1000), (int) (endTime / 1000),
status, flowPath);
results.add(azkabanJobExecRecord);
}
}
return results;
}
示例7: flatMap
import org.codehaus.jackson.JsonNode; //导入依赖的package包/类
@Override
public void flatMap(String tweetJsonStr, Collector<Tuple2<String, Integer>> collector) throws Exception {
JsonNode tweetJson = mapper.readTree(tweetJsonStr);
JsonNode entities = tweetJson.get("entities");
if (entities == null) return;
JsonNode hashtags = entities.get("hashtags");
if (hashtags == null) return;
for (Iterator<JsonNode> iter = hashtags.getElements(); iter.hasNext();) {
JsonNode node = iter.next();
String hashtag = node.get("text").getTextValue();
if (hashtag.matches("\\w+")) {
collector.collect(new Tuple2<>(hashtag, 1));
}
}
}
示例8: deserialize
import org.codehaus.jackson.JsonNode; //导入依赖的package包/类
@Override
public TopicRecord deserialize(JsonParser jp, DeserializationContext dc) throws IOException, JsonProcessingException {
JsonNode node = jp.getCodec().readTree(jp);
String topic = node.get("topic").asText();
long partition = node.get("partition").asLong();
long offset = node.get("offset").asLong();
long timestamp = node.get("timestamp").asLong();
String key = null;
if (node.has("key")) {
key = node.get("key").asText();
}
Map<Object, Object> value = new ObjectMapper().readValue(node.get("value").toString(), Map.class);
return new TopicRecord(topic, key, partition, offset, timestamp, value);
}
示例9: getCastOrCrew
import org.codehaus.jackson.JsonNode; //导入依赖的package包/类
private ArrayList<ResponseData> getCastOrCrew(String url, String type) {
ArrayList<ResponseData> datas = new ArrayList<>();
try {
JsonNode people = makeRequest(url).get(type);
List<String> peopleNames = new ArrayList<>();
for(JsonNode person : people) {
peopleNames.add(person.get("name").getTextValue());
}
if (peopleNames.size() > ResponseData.MAX_DATA_SIZE) {
peopleNames = peopleNames.subList(0, ResponseData.MAX_DATA_SIZE);
}
for (String personName : peopleNames) {
String uri = new LookupService().search(personName);
if(uri != null) {
datas.add(sparql.getEntityInformation(uri));
}
}
}
catch(Exception e) {
e.printStackTrace();
}
return datas;
}
示例10: deserialize
import org.codehaus.jackson.JsonNode; //导入依赖的package包/类
@Override
public ProducedEventsResult deserialize(JsonParser jp, DeserializationContext dc) throws IOException, JsonProcessingException {
JsonNode node = jp.getCodec().readTree(jp);
if (node.isArray()) {
List<ProducedEventResult> responses = new ArrayList<>();
Iterator<JsonNode> it = node.iterator();
while (it.hasNext()) {
JsonNode n = it.next();
responses.add(new ProducedEventResult(n.get("created").asBoolean()));
}
return new ProducedEventsResult(responses);
} else {
String reason = node.get("reason").asText();
return new ProducedEventsResult(reason);
}
}
示例11: deserializeIdentifiers
import org.codehaus.jackson.JsonNode; //导入依赖的package包/类
private Set<String> deserializeIdentifiers(final String aMultipleIdentifierKey,
final String aSingleIdentifierKey,
final JsonNode aRootNode) {
final Set<String> results = new HashSet<>();
final JsonNode multiNode = aRootNode.get(aMultipleIdentifierKey);
if (multiNode != null) {
for (final JsonNode node : multiNode) {
results.add(node.get(aSingleIdentifierKey).getValueAsText());
}
} else {
final JsonNode singleNode = aRootNode.get(aSingleIdentifierKey);
if ( singleNode != null) {
results.add(singleNode.getValueAsText());
}
}
return results;
}
示例12: getHostId
import org.codehaus.jackson.JsonNode; //导入依赖的package包/类
private String getHostId(String hostname) throws IOException {
String hostId = null;
URI uri = UriBuilder.fromUri(serverHostname)
.path("api")
.path(API_VERSION)
.path("hosts")
.build();
JsonNode hosts = getJsonNodeFromURIGet(uri);
if (hosts != null) {
// Iterate through the list of hosts, stopping once you've reached the requested hostname.
for (JsonNode host : hosts) {
if (host.get("hostname").getTextValue().equals(hostname)) {
hostId = host.get("hostId").getTextValue();
break;
}
}
} else {
hostId = null;
}
return hostId;
}
示例13: parseParameters
import org.codehaus.jackson.JsonNode; //导入依赖的package包/类
public static List<Parameter> parseParameters(JsonNode node){
JsonNode parametersNode=node.get("parameters");
if(parametersNode==null){
return null;
}
Iterator<JsonNode> iter=parametersNode.iterator();
List<Parameter> parameters=new ArrayList<Parameter>();
while(iter.hasNext()){
JsonNode parameterNode=iter.next();
Parameter param=new Parameter();
param.setName(getJsonValue(parameterNode, "name"));
String type=getJsonValue(parameterNode, "type");
if(type!=null){
param.setType(Datatype.valueOf(type));
}
String valueTypeText=getJsonValue(parameterNode, "valueType");
if(valueTypeText!=null){
param.setValue(parseValue(parameterNode));
}
param.setValue(parseValue(parameterNode));
parameters.add(param);
}
return parameters;
}
示例14: parseLines
import org.codehaus.jackson.JsonNode; //导入依赖的package包/类
private List<Line> parseLines(JsonNode node){
JsonNode lineNodes=node.get("lines");
if(lineNodes==null){
return null;
}
List<Line> lines=new ArrayList<Line>();
Iterator<JsonNode> iter=lineNodes.iterator();
while(iter.hasNext()){
JsonNode jsonNode=iter.next();
Line line=new Line();
line.setFromNodeId(jsonNode.get("fromNodeId").getIntValue());
line.setToNodeId(jsonNode.get("toNodeId").getIntValue());
lines.add(line);
}
return lines;
}
示例15: parseCriteriaUnit
import org.codehaus.jackson.JsonNode; //导入依赖的package包/类
private CriteriaUnit parseCriteriaUnit(JsonNode unitNode) {
CriteriaUnit unit=new CriteriaUnit();
JsonNode criteriaNode=unitNode.get("criteria");
if(criteriaNode!=null){
unit.setCriteria(parseCriteria(criteriaNode));
}
JsonNode junctionTypeNode=unitNode.get("junctionType");
if(junctionTypeNode!=null){
unit.setJunctionType(JunctionType.valueOf(junctionTypeNode.getTextValue()));
}
JsonNode nextUnitNodes=unitNode.get("nextUnits");
if(nextUnitNodes!=null){
List<CriteriaUnit> nextUnits=new ArrayList<CriteriaUnit>();
Iterator<JsonNode> iter=nextUnitNodes.iterator();
while(iter.hasNext()){
JsonNode nextNode=iter.next();
nextUnits.add(parseCriteriaUnit(nextNode));
}
unit.setNextUnits(nextUnits);
}
return unit;
}