org.codehaus.jackson.node.ArrayNode.get()方法的使用及代码示例

x33g5p2x  于11个月前 转载在 其他  
字(13.2k)|赞(0)|评价(0)|浏览(26)

本文整理了Java中org.codehaus.jackson.node.ArrayNode.get()方法的一些代码示例,展示了ArrayNode.get()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ArrayNode.get()方法的具体详情如下:
包路径:org.codehaus.jackson.node.ArrayNode
类名称:ArrayNode
方法名:get

ArrayNode.get介绍

暂无

代码示例

代码示例来源:origin: apache/nifi

final JsonNode jsonNode = arrayNode.get(i);

代码示例来源:origin: com.github.foodev/jsondiff

@Override
public JzonElement get(int index) {
  return JacksonWrapper.wrap(wrapped.get(index));
}

代码示例来源:origin: algesten/jsondiff

@Override
public JzonElement get(int index) {
  return JacksonWrapper.wrap(wrapped.get(index));
}

代码示例来源:origin: com.netflix.eureka/eureka2-core

private Object handleArray(JsonParser jp, ArrayNode arrayNode) throws IOException {
    Object[] arrayInstance = (Object[]) Array.newInstance(rawClass.getComponentType(), arrayNode.size());
    for (int i = 0; i < arrayInstance.length; i++) {
      Object value = handleObject(jp, arrayNode.get(i));
      arrayInstance[i] = value;
    }
    return arrayInstance;
  }
}

代码示例来源:origin: MrNeuronix/IRISv2

public List<Group> searchGroups(String query, int count, String token) throws IOException
{
  String request = String.format(groupsSearchUrl, URLEncoder.encode(query, "UTF-8"), 0, count, token);
  log.debug(request);
  HttpGet httpGet = new HttpGet(request);
  HttpResponse response = client.execute(httpGet);
  String responseBody = IOUtils.toString(response.getEntity().getContent(), "UTF-8");
  log.debug(responseBody);
  JsonNode resultTree = objectMapper.readTree(responseBody);
  ArrayNode arrayNode = (ArrayNode) resultTree.get("response");
  List<Group> groups = new ArrayList<>();
  for (int i = 1; i < arrayNode.size(); i++)
  {
    Group group = objectMapper.readValue(arrayNode.get(i).toString(), Group.class);
    groups.add(group);
  }
  return groups;
}

代码示例来源:origin: org.apache.stanbol/org.apache.stanbol.enhancer.nlp.json

private void parseAnnotations(Span span, Collection<Entry<String,JsonNode>> jAnnotations) throws IOException {
  for(Entry<String,JsonNode> jAnnotation : jAnnotations){
    if(jAnnotation.getValue().isObject()){
      parseAnnotation(span, jAnnotation.getKey(), (ObjectNode)jAnnotation.getValue());
    } else if(jAnnotation.getValue().isArray()){
      ArrayNode jValues = (ArrayNode)jAnnotation.getValue();
      for(int i=0;i< jValues.size();i++){
        JsonNode jValue = jValues.get(i);
        if(jValue.isObject()){
          parseAnnotation(span, jAnnotation.getKey(), (ObjectNode)jValue);
        } else {
          log.warn("unable to parse the {} value of the annotation {} "
            + "because value is no JSON object (ignored, json: {}",
            new Object[]{i,jAnnotation.getKey(),jAnnotation.getValue()});
        }
      }
    } else {
      log.warn("unable to parse Annotation {} because value is no JSON object (ignored, json: {}",
        jAnnotation.getKey(),jAnnotation.getValue());
    }
  }

}

代码示例来源:origin: apache/stanbol

private void parseAnnotations(Span span, Collection<Entry<String,JsonNode>> jAnnotations) throws IOException {
  for(Entry<String,JsonNode> jAnnotation : jAnnotations){
    if(jAnnotation.getValue().isObject()){
      parseAnnotation(span, jAnnotation.getKey(), (ObjectNode)jAnnotation.getValue());
    } else if(jAnnotation.getValue().isArray()){
      ArrayNode jValues = (ArrayNode)jAnnotation.getValue();
      for(int i=0;i< jValues.size();i++){
        JsonNode jValue = jValues.get(i);
        if(jValue.isObject()){
          parseAnnotation(span, jAnnotation.getKey(), (ObjectNode)jValue);
        } else {
          log.warn("unable to parse the {} value of the annotation {} "
            + "because value is no JSON object (ignored, json: {}",
            new Object[]{i,jAnnotation.getKey(),jAnnotation.getValue()});
        }
      }
    } else {
      log.warn("unable to parse Annotation {} because value is no JSON object (ignored, json: {}",
        jAnnotation.getKey(),jAnnotation.getValue());
    }
  }

}

代码示例来源:origin: hoverruan/weiboclient4j

public Map<Long, String> queryMidList(Collection<Id> idList, MidType midType) throws WeiboClientException {
  // [{"3436240135184587":"yfcLPlKKn"},{"3436255091659029":"yfd9X6XAx"}]
  ArrayNode arrayNode = doGet("statuses/querymid",
      withParams(Id.idParam(idList), midType, IsBatch.Yes), ArrayNode.class);
  Map<Long, String> map = new HashMap<Long, String>();
  for (int i = 0; i < arrayNode.size(); i++) {
    JsonNode node = arrayNode.get(i);
    Iterator<String> fieldNames = node.getFieldNames();
    while (fieldNames.hasNext()) {
      String idString = fieldNames.next();
      map.put(new Long(idString), node.get(idString).asText());
    }
  }
  return map;
}

代码示例来源:origin: hoverruan/weiboclient4j

public <T extends QueryIdListParam> Map<String, Long> queryIdList(
    Collection<Mid> midList, MidType type, T... optionalParams)
    throws WeiboClientException {
  // [{"yfcLPlKKn":"3436240135184587"},{"yfd9X6XAx":"3436255091659029"}]
  ArrayNode arrayNode = doGet("statuses/queryid", buildParams(optionalParams, Mid.midParam(midList), type,
      IsBatch.Yes), ArrayNode.class);
  Map<String, Long> map = new HashMap<String, Long>();
  for (int i = 0; i < arrayNode.size(); i++) {
    JsonNode node = arrayNode.get(i);
    Iterator<String> fieldNames = node.getFieldNames();
    while (fieldNames.hasNext()) {
      String mid = fieldNames.next();
      map.put(mid, node.get(mid).asLong());
    }
  }
  return map;
}

代码示例来源:origin: corydissinger/raw4j

@SuppressWarnings("unchecked")
private RedditComments mapJsonComments(final int limit) throws RedditException{
  final JsonNode parentLinkNode	= rootNode.get(0);
  final JsonNode commentsNode		= rootNode.get(1);
  final ArrayNode childrenNode  	= (ArrayNode)commentsNode.get(RedditJsonConstants.DATA)
                       .get(RedditJsonConstants.CHILDREN);
  final JsonNode moreNode			= childrenNode.get(childrenNode.size() - 1);
  final boolean moreExists		= moreNode.get(RedditJsonConstants.KIND).asText().equals("more");
  
  //See the 'replies' attribute of RedditComment. It is a JsonNode
  final List<RedditLink> theParentLink	   = (List<RedditLink>) parseSpecificType(parentLinkNode, RedditJsonConstants.TYPE_LINK);
  final List<RedditComment> topLevelComments = (List<RedditComment>) parseSpecificType(rootNode, RedditJsonConstants.TYPE_COMMENT);		
  if(moreExists){
    final RedditMore theMore;
    
    try {
      theMore = mapper.readValue(moreNode.get(RedditJsonConstants.DATA), RedditMore.class);
    } catch (Exception e) {
      throw new RedditException(e);
    }
    
    return new RedditComments(theParentLink.get(0), topLevelComments, theMore);			
  }else{
    //Return non-null default reddit more with count of 0
    return new RedditComments(theParentLink.get(0), topLevelComments, new RedditMore());			
  }
}

代码示例来源:origin: NGDATA/lilyproject

public BlobStoreAccessConfig(byte[] encodedConfig) {
  JsonNode node = JsonFormat.deserializeSoft(encodedConfig, "BlobStoreAccessConfig");
  defaultAccess = JsonUtil.getString(node, "default");
  ArrayNode limitsNode = JsonUtil.getArray(node, "limits");
  for (int i = 0; i < limitsNode.size(); i++) {
    JsonNode limitNode = limitsNode.get(i);
    String store = JsonUtil.getString(limitNode, "store");
    long limit = JsonUtil.getLong(limitNode, "limit");
    limits.put(store, limit);
  }
}

代码示例来源:origin: eBay/YiDB

private void getExecutedMetaClass(IQueryResult result, QueryContext cmsdbContext) {
  MetaClass mc = cmsdbMetaService.getMetaClass("NodeServer");
  MetaField field = mc.getFieldByName("networkAddress");
  ArrayNode andNodes = (ArrayNode) result.getExplanations().get(1)
      .getJsonExplanation().get("criteria").get("$and");
  boolean hasId = false;
  // FIXME: flatten will have different explanation
  if (cmsdbContext.getRegistration().registrationId.equals("hierarchy")) {
    JsonNode node = andNodes.get(1).get("$and").get(0).get("$and").get(1);
    hasId |= node.has(field.getValueDbName() + "._i");
    Assert.assertTrue(hasId);
  }
}

代码示例来源:origin: NGDATA/lilyproject

/**
 * Extracts field types declared inline in a record type. An inline definition is recognized by the
 * presence of a valueType attribute on the field. Found field types are added to the passed map after
 * checking for conflicting definitions.
 */
private void extractFieldTypesFromRecordType(JsonNode node, Map<QName, FieldType> fieldTypes)
    throws RepositoryException, InterruptedException, JsonFormatException, ImportException {
  if (node.has("fields")) {
    ArrayNode fields = getArray(node, "fields");
    for (int i = 0; i < fields.size(); i++) {
      JsonNode field = fields.get(i);
      if (field.has("valueType")) {
        FieldType fieldType = parseFieldType(field);
        if (fieldTypes.containsKey(fieldType.getName())) {
          FieldType prevFieldType = fieldTypes.get(fieldType.getName());
          if (!fieldType.equals(prevFieldType)) {
            throw new ImportException("Found conflicting definitions of a field type in two record"
                + " types, field types: " + fieldType + " and " + prevFieldType);
          }
        } else {
          fieldTypes.put(fieldType.getName(), fieldType);
        }
      }
    }
  }
}

代码示例来源:origin: eBay/YiDB

@Test
public void testProjection09() {
  String query = "ApplicationService[@resourceId=~\"srp-app.*\"]{*}.accessPoints{*}";
  cmsdbContext.setShowDisplayMeta(true);
  cmsdbContext.setAllowFullTableScan(true);
  IQueryResult result = queryService.query(query, cmsdbContext);
  Assert.assertNotNull(result.getDisplayMeta());
  ObjectNode apDisplay = (ObjectNode) result.getDisplayMeta().get(0).get("fields").get("accessPoints")
      .get("refDataType").get("AccessPoint").get("fields");
  MetaClass meta = cmsdbMetaService.getMetaClass("AccessPoint");
  Assert.assertEquals(meta.getFieldNames().size(), apDisplay.size());
}

代码示例来源:origin: oVirt/ovirt-engine

@Test
public void testGetPluginDefinitionsArray() {
  int mockDataCount = 10;
  List<PluginData> pluginData = new ArrayList<>();
  for (int i = 0; i < mockDataCount; i++) {
    PluginData mockData = mock(PluginData.class);
    when(mockData.getName()).thenReturn("name" + i); //$NON-NLS-1$
    when(mockData.getUrl()).thenReturn("url" + i); //$NON-NLS-1$
    when(mockData.mergeConfiguration()).thenReturn(mock(ObjectNode.class));
    when(mockData.isEnabled()).thenReturn(true);
    pluginData.add(mockData);
  }
  ArrayNode result = testServlet.getPluginDefinitionsArray(pluginData);
  assertEquals(mockDataCount, result.size());
  for (int i = 0; i < mockDataCount; i++) {
    JsonNode item = result.get(i);
    assertEquals(item.get("name").asText(), "name" + i); //$NON-NLS-1$ //$NON-NLS-2$
    assertEquals(item.get("url").asText(), "url" + i); //$NON-NLS-1$ //$NON-NLS-2$
    assertTrue(item.get("config") instanceof ObjectNode); //$NON-NLS-1$
    assertTrue(item.get("enabled").asBoolean()); //$NON-NLS-1$
  }
}

代码示例来源:origin: NGDATA/lilyproject

private MetadataBuilder readMetadataToDelete(JsonNode metadataToDelete, MetadataBuilder builder,
    QName recordField) throws JsonFormatException {
  if (!metadataToDelete.isArray()) {
    throw new JsonFormatException("The value for the metadataToDelete should be an array, field: " + recordField);
  }
  ArrayNode array = (ArrayNode)metadataToDelete;
  if (builder == null) {
    builder = new MetadataBuilder();
  }
  for (int i = 0; i < array.size(); i++) {
    JsonNode entry = array.get(i);
    if (!entry.isTextual()) {
      throw new JsonFormatException("Non-string found in the metadataToDelete array of field: " + recordField);
    }
    builder.delete(entry.getTextValue());
  }
  return builder;
}

代码示例来源:origin: eBay/YiDB

/**
 * Set query
 */
@Test
public void testProject07() {
  raptorContext.setAllowFullTableScan(true);
  raptorContext.setShowDisplayMeta(true);
  String query = "ApplicationService.(services{@_oid}&&updateStrategies{@_type})";
  IQueryResult result = queryService.query(query, raptorContext);
  ArrayNode display = result.getDisplayMeta();
  Assert.assertEquals(2, display.size());
  ObjectNode servDisplay = (ObjectNode) display.get(0).get("fields");
  Assert.assertEquals(2, servDisplay.size());
  ObjectNode usDisplay = (ObjectNode) display.get(1).get("fields");
  Assert.assertEquals(2, usDisplay.size());
}

代码示例来源:origin: bedatadriven/activityinfo

@Test
public void filterByPartner() throws IOException {
  final int partnerId = 2;
  QueryParameters parameters = new QueryParameters();
  parameters.partnerIds.add(partnerId);
  String json = query(parameters);
  System.out.println(json);
  final ArrayNode jsonNode = (ArrayNode) Jackson.createJsonMapper().readTree(json);
  assertEquals(jsonNode.get(0).path("partner").path("id").asInt(), partnerId);
}

代码示例来源:origin: eBay/YiDB

@Test
public void testProject08() {
  String query = "Rack{@location}.assets.asset!AssetServer{@resourceId,@faultDomain}";
  cmsdbContext.setAllowFullTableScan(true);
  cmsdbContext.setShowDisplayMeta(true);
  IQueryResult result = queryService.query(query, cmsdbContext);
  Assert.assertNotNull(result.getDisplayMeta());
  Assert.assertEquals(1, result.getDisplayMeta().size());
  // reverse
  ObjectNode rackDisplay = (ObjectNode) result.getDisplayMeta().get(0).get("fields");
  Assert.assertEquals(4, rackDisplay.size());
  ObjectNode assetDisplay = (ObjectNode) rackDisplay.get("assets").get("refDataType").get("Asset").get("fields");
  Assert.assertEquals(3, assetDisplay.size());
  ObjectNode assetServerDisplay = (ObjectNode) assetDisplay.get("asset!AssetServer").get("refDataType")
      .get("AssetServer").get("fields");
  Assert.assertEquals(4, assetServerDisplay.size());
}

代码示例来源:origin: eBay/YiDB

@Test
public void testProject06() {
  // case 0 : aggregation
  String query = "NetworkAddress<@healthState>{@healthState, $max(@address), $count()}";
  cmsdbContext.setAllowFullTableScan(true);
  cmsdbContext.setShowDisplayMeta(true);
  IQueryResult result = queryService.query(query, cmsdbContext);
  ArrayNode display = result.getDisplayMeta();
  ObjectNode na = (ObjectNode) display.get(0).get("fields");
  Assert.assertEquals(5, na.size());
  Assert.assertTrue(na.has("healthState"));
  Assert.assertTrue(na.has("$count"));
  Assert.assertTrue(na.has("$max_address"));
}

相关文章