本文整理匯總了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();
}
}
}