本文整理汇总了Java中com.fasterxml.jackson.databind.JsonNode.withArray方法的典型用法代码示例。如果您正苦于以下问题:Java JsonNode.withArray方法的具体用法?Java JsonNode.withArray怎么用?Java JsonNode.withArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.fasterxml.jackson.databind.JsonNode
的用法示例。
在下文中一共展示了JsonNode.withArray方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getResultListFromJson
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private ArrayList<JsonNode> getResultListFromJson(JsonNode response) {
ArrayList<JsonNode> resultList = new ArrayList<>();
// ignore case when parsing items array
String itemsKey = response.has("Items") ? "Items" : "items";
for (JsonNode item : response.withArray(itemsKey)) {
try {
resultList.add(item);
} catch (Exception e) {
log.error("Could not parse data from Key Value Storage");
throw new CompletionException(
new ExternalDependencyException(
"Could not parse data from Key Value Storage"));
}
}
return resultList;
}
示例2: setDatabaseFieldProperties
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
public static void setDatabaseFieldProperties(String dbName,String field_name, String propName, ObjectNode objNode ) throws IOException{
InputStream jsonstream=null;
try{
DefaultHttpClient client = new DefaultHttpClient();
client.getCredentialsProvider().setCredentials(
new AuthScope(host, 8002),
new UsernamePasswordCredentials("admin", "admin"));
HttpGet getrequest = new HttpGet("http://"+host+":8002"+ "/manage/v2/databases/"+dbName+"/properties?format=json");
HttpResponse response1 = client.execute(getrequest);
jsonstream =response1.getEntity().getContent();
ObjectMapper mapper = new ObjectMapper();
JsonNode jnode= mapper.readTree(jsonstream);
if(!jnode.isNull()&& jnode.has("field")){
JsonNode fieldNode = jnode.withArray("field");
Iterator<JsonNode> fnode = fieldNode.elements();
while(fnode.hasNext()) {
JsonNode fnchild =fnode.next();
if((fnchild.path("field-name").asText()).equals(field_name)){
// System.out.println("Hurray" +fnchild.has(propName));
if(!fnchild.has(propName)){
((ObjectNode)fnchild).putArray(propName).addAll(objNode.withArray(propName));
// System.out.println("Adding child array include node" + jnode.toString());
}
else{
JsonNode member = fnchild.withArray(propName);
((ArrayNode)member).addAll(objNode.withArray(propName));
}
}
}
HttpPut put = new HttpPut("http://"+host+":8002"+ "/manage/v2/databases/"+dbName+"/properties?format=json");
put.addHeader("Content-type", "application/json");
put.setEntity(new StringEntity(jnode.toString()));
HttpResponse response2 = client.execute(put);
HttpEntity respEntity = response2.getEntity();
if(respEntity != null){
String content = EntityUtils.toString(respEntity);
System.out.println(content);
}
}
else{
System.out.println("REST call for database properties returned NULL \n"+jnode.toString()+"\n"+ response1.getStatusLine().getStatusCode());
}
}catch (Exception e) {
// writing error to Log
e.printStackTrace();
}
finally{
if(jsonstream == null){}
else{
jsonstream.close();
}
}
}