com.fasterxml.jackson.databind.JsonNode.fields()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(10.0k)|赞(0)|评价(0)|浏览(240)

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

JsonNode.fields介绍

暂无

代码示例

代码示例来源:origin: redisson/redisson

@Override
protected void _depositSchemaProperty(ObjectNode propertiesNode, JsonNode schemaNode)
{
  JsonNode props = schemaNode.get("properties");
  if (props != null) {
    Iterator<Entry<String, JsonNode>> it = props.fields();
    while (it.hasNext()) {
      Entry<String,JsonNode> entry = it.next();
      String name = entry.getKey();
      if (_nameTransformer != null) {
        name = _nameTransformer.transform(name);
      }
      propertiesNode.set(name, entry.getValue());
    }
  }
}

代码示例来源:origin: apache/incubator-druid

@Override
public Iterable<String> discoverRootFields(final JsonNode obj)
{
 return FluentIterable.from(() -> obj.fields())
            .filter(
              entry -> {
               final JsonNode val = entry.getValue();
               return !(val.isObject() || val.isNull() || (val.isArray() && !isFlatList(val)));
              }
            )
            .transform(Map.Entry::getKey);
}

代码示例来源:origin: docker-java/docker-java

@Override
  public ExposedPort deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
      throws IOException, JsonProcessingException {
    ObjectCodec oc = jsonParser.getCodec();
    JsonNode node = oc.readTree(jsonParser);
    if (!node.equals(NullNode.getInstance())) {
      Entry<String, JsonNode> field = node.fields().next();
      return ExposedPort.parse(field.getKey());
    } else {
      return null;
    }
  }
}

代码示例来源:origin: aws/aws-sdk-java

/**
 * Transforms the {@link JsonNode} into a map to integrate with the {@link SignatureChecker} utility.
 *
 * @param messageJson JSON of message.
 * @return Transformed map.
 */
private Map<String, String> toMap(JsonNode messageJson) {
  Map<String, String> fields = new HashMap<String, String>(messageJson.size());
  Iterator<Map.Entry<String, JsonNode>> jsonFields = messageJson.fields();
  while (jsonFields.hasNext()) {
    Map.Entry<String, JsonNode> next = jsonFields.next();
    fields.put(next.getKey(), next.getValue().asText());
  }
  return fields;
}

代码示例来源:origin: docker-java/docker-java

@Override
  public VolumeRW deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
      throws IOException, JsonProcessingException {
    ObjectCodec oc = jsonParser.getCodec();
    JsonNode node = oc.readTree(jsonParser);
    if (!node.equals(NullNode.getInstance())) {
      Entry<String, JsonNode> field = node.fields().next();
      String volume = field.getKey();
      AccessMode accessMode = AccessMode.fromBoolean(field.getValue().asBoolean());
      return new VolumeRW(new Volume(volume), accessMode);
    } else {
      return null;
    }
  }
}

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

private Map<String, JsonNode> parseAsJson(byte[] value) throws IOException {
 JsonNode document = mapper.readValue(value, JsonNode.class);
 //Hive Column names are case insensitive.
 Map<String, JsonNode> documentMap = Maps.newTreeMap(String.CASE_INSENSITIVE_ORDER);
 document.fields().forEachRemaining(field -> documentMap.put(field.getKey().toLowerCase(), field.getValue()));
 return documentMap;
}

代码示例来源:origin: testcontainers/testcontainers-java

private Map.Entry<String, JsonNode> findAuthNode(final JsonNode config, final String reposName) {
  final JsonNode auths = config.get("auths");
  if (auths != null && auths.size() > 0) {
    final Iterator<Map.Entry<String, JsonNode>> fields = auths.fields();
    while (fields.hasNext()) {
      final Map.Entry<String, JsonNode> entry = fields.next();
      if (entry.getKey().contains("://" + reposName) || entry.getKey().equals(reposName)) {
        return entry;
      }
    }
  }
  return null;
}

代码示例来源:origin: galenframework/galen

public List<PageItem> loadItems(InputStream stream) throws IOException {
  JsonNode jsonTree = mapper.readTree(stream);
  List<PageItem> items = new LinkedList<>();
  jsonTree.get("items").fields().forEachRemaining(itemEntry -> {
    items.add(new PageItem(itemEntry.getKey(), readArea(itemEntry.getValue())));
  });
  return items;
}

代码示例来源:origin: bootique/bootique

private String getChildCiKey(JsonNode parent, String fieldName) {
  fieldName = fieldName.toUpperCase();
  Iterator<Entry<String, JsonNode>> fields = parent.fields();
  while (fields.hasNext()) {
    Entry<String, JsonNode> f = fields.next();
    if (fieldName.equalsIgnoreCase(f.getKey())) {
      return f.getKey();
    }
  }
  return fieldName;
}

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

final Iterable<Map.Entry<String, JsonNode>> iterable = () -> jsonNode.fields();
  cursors.put( Integer.parseInt( node.getKey() ), node.getValue() );

代码示例来源:origin: Graylog2/graylog2-server

public Set<IndexStatistics> getIndicesStats(final Collection<String> indices) {
  final ImmutableSet.Builder<IndexStatistics> result = ImmutableSet.builder();
  final JsonNode allWithShardLevel = getAllWithShardLevel(indices);
  final Iterator<Map.Entry<String, JsonNode>> fields = allWithShardLevel.fields();
  while (fields.hasNext()) {
    final Map.Entry<String, JsonNode> entry = fields.next();
    final String index = entry.getKey();
    final JsonNode indexStats = entry.getValue();
    if (indexStats.isObject()) {
      result.add(buildIndexStatistics(index, indexStats));
    }
  }
  return result.build();
}

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

@Override
public RedisStateMap deserialize(final byte[] data) throws IOException {
  if (data == null || data.length == 0) {
    return null;
  }
  final RedisStateMap.Builder builder = new RedisStateMap.Builder();
  try (final JsonParser jsonParser = jsonFactory.createParser(data)) {
    final JsonNode rootNode = jsonParser.readValueAsTree();
    builder.version(rootNode.get(FIELD_VERSION).asLong());
    builder.encodingVersion(rootNode.get(FIELD_ENCODING).asInt());
    final JsonNode stateValuesNode = rootNode.get(FIELD_STATE_VALUES);
    stateValuesNode.fields().forEachRemaining(e -> builder.stateValue(e.getKey(), e.getValue().asText()));
  }
  return builder.build();
}

代码示例来源:origin: prestodb/presto

private List<String> getColumnMetadata(Optional<String> parent, JsonNode propertiesNode)
{
  ImmutableList.Builder<String> metadata = ImmutableList.builder();
  Iterator<Entry<String, JsonNode>> iterator = propertiesNode.fields();
  while (iterator.hasNext()) {
    Entry<String, JsonNode> entry = iterator.next();
    String key = entry.getKey();
    JsonNode value = entry.getValue();
    String childKey;
    if (parent.isPresent()) {
      if (parent.get().isEmpty()) {
        childKey = key;
      }
      else {
        childKey = parent.get().concat(".").concat(key);
      }
    }
    else {
      childKey = key;
    }
    if (value.isObject()) {
      metadata.addAll(getColumnMetadata(Optional.of(childKey), value));
      continue;
    }
    if (!value.isArray()) {
      metadata.add(childKey.concat(":").concat(value.textValue()));
    }
  }
  return metadata.build();
}

代码示例来源:origin: Graylog2/graylog2-server

final Spliterator<Map.Entry<String, JsonNode>> fieldSpliterator = Spliterators.spliteratorUnknownSize(properties.fields(), Spliterator.IMMUTABLE);
    .map(field -> Maps.immutableEntry(field.getKey(), field.getValue().path("type").asText()))
    .filter(field -> !field.getValue().isEmpty())
    .map(field -> FieldTypeDTO.create(field.getKey(), field.getValue()))
    .collect(Collectors.toSet());

代码示例来源:origin: twosigma/beakerx

@Override
public Object deserialize(JsonNode n, ObjectMapper mapper) {
 HashMap<String, Object> o = new HashMap<String,Object>();
 try {
  logger.debug("using custom map deserializer");
  Iterator<Entry<String, JsonNode>> e = n.fields();
  while(e.hasNext()) {
   Entry<String, JsonNode> ee = e.next();
   o.put(ee.getKey(), parent.deserialize(ee.getValue(),mapper));
  }
 } catch (Exception e) {
  logger.error("exception deserializing Map ", e);
  o = null;
 }
 return o;
}

代码示例来源:origin: aws/aws-sdk-java

/**
 * Generates a list of condition from the Json node.
 *
 * @param conditionNodes
 *            the condition Json node to be parsed.
 * @return the list of conditions.
 */
private List<Condition> conditionsOf(JsonNode conditionNodes) {
  List<Condition> conditionList = new LinkedList<Condition>();
  Iterator<Map.Entry<String, JsonNode>> mapOfConditions = conditionNodes
      .fields();
  Entry<String, JsonNode> condition;
  while (mapOfConditions.hasNext()) {
    condition = mapOfConditions.next();
    convertConditionRecord(conditionList, condition.getKey(),
        condition.getValue());
  }
  return conditionList;
}

代码示例来源:origin: Graylog2/graylog2-server

private static List<ShardRouting> buildShardRoutings(JsonNode shardRoutings) {
  final ImmutableList.Builder<ShardRouting> shardRoutingsBuilder = ImmutableList.builder();
  final Iterator<Map.Entry<String, JsonNode>> it = shardRoutings.fields();
  while (it.hasNext()) {
    final Map.Entry<String, JsonNode> entry = it.next();
    final int shardId = Integer.parseInt(entry.getKey());
    final JsonNode shards = entry.getValue();

代码示例来源:origin: opentripplanner/OpenTripPlanner

/** This converts everything to Strings and back, but it does work, and avoids a bunch of type conditionals. */
public T scrape(JsonNode rootNode) {
  Map<String, String> pairs = Maps.newHashMap();
  // Ugh, there has to be a better way to do this.
  Iterator<Map.Entry<String, JsonNode>> fieldIterator = rootNode.fields();
  while (fieldIterator.hasNext()) {
    Map.Entry<String, JsonNode> field = fieldIterator.next();
    pairs.put(field.getKey(), field.getValue().asText());
  }
  return scrape(pairs);
}

代码示例来源:origin: twosigma/beakerx

@Override
 public Object deserialize(JsonNode n, ObjectMapper mapper) {
  HashMap<String, Object> map = new HashMap<String, Object>();
  Iterator<Map.Entry<String, JsonNode>> entries = n.fields();
  while (entries.hasNext()) {
   try {
    Map.Entry<String, JsonNode> ee = entries.next();
    map.put(ee.getKey(), parent.deserialize(ee.getValue(), mapper));
   } catch (Exception e) {
    LoggerFactory.getLogger(this.getClass().getName()).error(e.getMessage());
   }
  }
  return PersistentArrayMap.create(map);
 }
}

代码示例来源:origin: knowm/XChange

@Override
 public YoBitOrderBooksReturn deserialize(JsonParser p, DeserializationContext ctxt)
   throws IOException {

  JsonNode node = p.readValueAsTree();
  Map<String, YoBitOrderBook> tickers = new HashMap<>();

  if (node.isObject()) {
   Iterator<Map.Entry<String, JsonNode>> priceEntryIter = node.fields();

   while (priceEntryIter.hasNext()) {
    Map.Entry<String, JsonNode> priceEntryNode = priceEntryIter.next();

    JsonNode jsonNode = priceEntryNode.getValue();
    ObjectReader jsonObjectReader = new ObjectMapper().readerFor(YoBitOrderBook.class);
    YoBitOrderBook orderBook = jsonObjectReader.readValue(jsonNode);
    String ccy = priceEntryNode.getKey();

    tickers.put(ccy, orderBook);
   }
  }

  return new YoBitOrderBooksReturn(tickers);
 }
}

相关文章