org.codehaus.jackson.JsonNode.getFields()方法的使用及代码示例

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

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

JsonNode.getFields介绍

暂无

代码示例

代码示例来源:origin: brianfrankcooper/YCSB

protected static void fromJson(
  String value, Set<String> fields,
  Map<String, ByteIterator> result) throws IOException {
 JsonNode json = MAPPER.readTree(value);
 boolean checkFields = fields != null && !fields.isEmpty();
 for (Iterator<Map.Entry<String, JsonNode>> jsonFields = json.getFields();
    jsonFields.hasNext();
    /* increment in loop body */) {
  Map.Entry<String, JsonNode> jsonField = jsonFields.next();
  String name = jsonField.getKey();
  if (checkFields && !fields.contains(name)) {
   continue;
  }
  JsonNode jsonValue = jsonField.getValue();
  if (jsonValue != null && !jsonValue.isNull()) {
   result.put(name, new StringByteIterator(jsonValue.asText()));
  }
 }
}

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

/**
 * Instantiate a new keystore using the file at the provided path
 */
public JsonCredentialStore(Path path, KeyToStringCodec codec) throws IOException {
 credentials =  new HashMap<>();
 FileSystem fs = path.getFileSystem(new Configuration());
 try (InputStream in = fs.open(path)) {
  ObjectMapper jsonParser = defaultMapper;
  JsonNode tree = jsonParser.readTree(in);
  if (!tree.isObject()) {
   throw new IllegalArgumentException("Json in " + path.toString() + " is not an object!");
  }
  Iterator<Map.Entry<String, JsonNode>> it = tree.getFields();
  while (it.hasNext()) {
   Map.Entry<String, JsonNode> field = it.next();
   String keyId = field.getKey();
   byte[] key = codec.decodeKey(field.getValue().getTextValue());
   credentials.put(keyId, key);
  }
 }
 log.info("Initialized keystore from {} with {} keys", path.toString(), credentials.size());
}

代码示例来源:origin: io.snamp/json-helpers

public static void exportToMap(final JsonNode node, final Map<String, Object> output, final Predicate<String> fieldFilter) {
    node.getFields().forEachRemaining(field -> {
      if (fieldFilter.test(field.getKey()))
        output.put(field.getKey(), field.getValue());
    });
  }
}

代码示例来源:origin: org.apache.isis.viewer/json-applib

public Iterator<Map.Entry<String, JsonRepresentation>> mapIterator() {
  ensureIsAMap();
  return Iterators.transform(jsonNode.getFields(), MAP_ENTRY_JSON_NODE_TO_JSON_REPRESENTATION);
}

代码示例来源:origin: org.apache.isis.viewer/isis-viewer-restfulobjects-applib

public Iterator<Map.Entry<String, JsonRepresentation>> mapIterator() {
  ensureIsAMap();
  return Iterators.transform(jsonNode.getFields(), MAP_ENTRY_JSON_NODE_TO_JSON_REPRESENTATION);
}

代码示例来源:origin: com.indeed/lsmtree-recordlog

private static Map<String, String> readMetadata(File metadataPath, ObjectMapper mapper) throws IOException {
  if (metadataPath.exists()) {
    Map<String, String> ret = Maps.newLinkedHashMap();
    JsonNode node = mapper.readTree(Files.toString(metadataPath, Charsets.UTF_8));
    Iterator<Map.Entry<String,JsonNode>> iterator = node.getFields();
    while (iterator.hasNext()) {
      Map.Entry<String, JsonNode> entry = iterator.next();
      ret.put(entry.getKey(), entry.getValue().getTextValue());
    }
    return ret;
  }
  return null;
}

代码示例来源:origin: indeedeng/lsmtree

private static Map<String, String> readMetadata(File metadataPath, ObjectMapper mapper) throws IOException {
  if (metadataPath.exists()) {
    Map<String, String> ret = Maps.newLinkedHashMap();
    JsonNode node = mapper.readTree(Files.toString(metadataPath, Charsets.UTF_8));
    Iterator<Map.Entry<String,JsonNode>> iterator = node.getFields();
    while (iterator.hasNext()) {
      Map.Entry<String, JsonNode> entry = iterator.next();
      ret.put(entry.getKey(), entry.getValue().getTextValue());
    }
    return ret;
  }
  return null;
}

代码示例来源:origin: dessalines/torrenttunes-client

private Strings(String jsonLocation) {
  
  map = new HashMap<String, Map<String, String>>();
  
  String json = Tools.readFile(jsonLocation);
  
  JsonNode node = Tools.jsonToNode(json);
  
  Map<String, String> innerMap = new HashMap<String, String>();
  
  // Iterate over all the string fields
  JsonNode s = node.get("strings");
  
  Iterator<Entry<String, JsonNode>> sIt = s.getFields();
  while (sIt.hasNext()) {
    Entry<String, JsonNode> e = sIt.next();
    
    innerMap.put(e.getKey(), e.getValue().asText());
  }
  
  map.put("strings", innerMap);
  
}

代码示例来源:origin: org.eagle-i/eagle-i-datatools-catalyst

private Map<String, Set<String>> extractTextProperties(JsonNode node) {
  Map<String, Set<String>> resultMap = new HashMap<String, Set<String>>();
  
  // get an iterator to the fields
  Iterator<Entry<String, JsonNode>> nodeIterator = node.getFields();
  while ( nodeIterator.hasNext() ) {
    Entry<String, JsonNode> oneEntry = nodeIterator.next();
    String key = oneEntry.getKey();
    Set<String> valueSet = new HashSet<String>();
    
    JsonNode valueNodes = oneEntry.getValue();
    if ( valueNodes != null ) {
      for ( JsonNode oneValue : valueNodes ) {
        if ( oneValue != null ) {
          valueSet.add( extractTextNode( oneValue ) );
        }
      }
    }
    
    resultMap.put( key, valueSet );
  }
  
  return resultMap;
}

代码示例来源:origin: mobi.boilr/libdynticker

@Override
protected List<Pair> getPairsFromAPI() throws IOException {
  List<Pair> pairs = new ArrayList<Pair>();
  Iterator<Map.Entry<String,JsonNode>> elements = readJsonFromUrl(API_URL).getFields();
  String[] split;
  for(Map.Entry<String,JsonNode> entry; elements.hasNext();) {
    entry = elements.next();
    if(!entry.getValue().get("last_price").asText().isEmpty()) {
      split = entry.getKey().split("_");
      pairs.add(new Pair(split[0], split[1]));
    }
  }
  return pairs;
}

代码示例来源:origin: com.linkedin.gobblin/gobblin-crypto

/**
 * Instantiate a new keystore using the file at the provided path
 */
public JsonCredentialStore(Path path, KeyToStringCodec codec) throws IOException {
 credentials =  new HashMap<>();
 FileSystem fs = path.getFileSystem(new Configuration());
 try (InputStream in = fs.open(path)) {
  ObjectMapper jsonParser = defaultMapper;
  JsonNode tree = jsonParser.readTree(in);
  if (!tree.isObject()) {
   throw new IllegalArgumentException("Json in " + path.toString() + " is not an object!");
  }
  Iterator<Map.Entry<String, JsonNode>> it = tree.getFields();
  while (it.hasNext()) {
   Map.Entry<String, JsonNode> field = it.next();
   String keyId = field.getKey();
   byte[] key = codec.decodeKey(field.getValue().getTextValue());
   credentials.put(keyId, key);
  }
 }
 log.info("Initialized keystore from {} with {} keys", path.toString(), credentials.size());
}

代码示例来源:origin: org.apache.gobblin/gobblin-crypto

/**
 * Instantiate a new keystore using the file at the provided path
 */
public JsonCredentialStore(Path path, KeyToStringCodec codec) throws IOException {
 credentials =  new HashMap<>();
 FileSystem fs = path.getFileSystem(new Configuration());
 try (InputStream in = fs.open(path)) {
  ObjectMapper jsonParser = defaultMapper;
  JsonNode tree = jsonParser.readTree(in);
  if (!tree.isObject()) {
   throw new IllegalArgumentException("Json in " + path.toString() + " is not an object!");
  }
  Iterator<Map.Entry<String, JsonNode>> it = tree.getFields();
  while (it.hasNext()) {
   Map.Entry<String, JsonNode> field = it.next();
   String keyId = field.getKey();
   byte[] key = codec.decodeKey(field.getValue().getTextValue());
   credentials.put(keyId, key);
  }
 }
 log.info("Initialized keystore from {} with {} keys", path.toString(), credentials.size());
}

代码示例来源:origin: stackoverflow.com

JSONParser jsonParser = new JSONParser();
             JSONObject jsonObject = (JSONObject) jsonParser.parse(obj);
             JSONArray lang = (JSONArray) jsonObject.get("Headlines");
             for (int i = 0; i < lang.size(); i++) {
               JSONObject jsonobject = (JSONObject) lang.get(i);
               Object subArray = jsonobject.get("Tags");
               ObjectMapper mapperNew = new ObjectMapper();
               JsonFactory factoryNew = mapperNew.getJsonFactory();
               JsonParser jpNew;
               System.out.println("sub Array " + subArray.toString());
               jpNew = factoryNew.createJsonParser(subArray.toString());
               JsonNode inputNew = mapperNew.readTree(jpNew);
                for (final JsonNode elementNew : inputNew) {
                  Iterator<Map.Entry<String, JsonNode>> nodeIterator3 = elementNew.getFields();
                   while (nodeIterator3.hasNext()) {
                      Map.Entry<String, JsonNode> entry3 = (Map.Entry<String, JsonNode>) nodeIterator3.next();
                       if (entry3.getKey() != null && entry3.getKey().equals("TagType")) {
                          System.out.println("TagType "  + entry3.getValue());
                        }
                        if (entry3.getKey() != null && entry3.getKey().equals("TagValues")) {
                          System.out.println("TagValues " + entry3.getValue());
                        }
                   }
                }

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

private static Map<String, Object> extractMeasuresFromComplexType(final String parentMeasureName, final JsonNode jsonNode) {
 final Map<String, Object> unwrappedValues = new HashMap<String, Object>();
 if (jsonNode.isContainerNode()) {
  final Iterator<Entry<String, JsonNode>> i = jsonNode.getFields();
  while (i.hasNext()) {
   final Entry<String, JsonNode> childEntry = i.next();
   unwrappedValues.putAll(extractMeasuresFromComplexType(parentMeasureName + "." + childEntry.getKey(), childEntry.getValue()));
  }
 } else {
  final String measureName = parentMeasureName;
  try {
   final Object value = getSimpleValue(jsonNode.asText());
   unwrappedValues.put(measureName, value);
  } catch (final ParseException pe) {
   // probably String or some non-numeric value. Pass
  }
 }
 return unwrappedValues;
}

代码示例来源:origin: io.snamp/json-helpers

private static CompositeType deserializeCompositeType(final JsonNode json) throws JsonProcessingException {
  final String typeName = json.get(TYPE_NAME_FIELD).asText();
  final String description = json.get(DESCRIPTION_FIELD).asText();
  final List<String> itemNames = new LinkedList<>();
  final List<String> itemDescriptions = new LinkedList<>();
  final List<OpenType<?>> itemTypes = new LinkedList<>();
  final Iterator<Map.Entry<String, JsonNode>> items = json.get(ITEMS_FIELD).getFields();
  while (items.hasNext()) {
    final Map.Entry<String, JsonNode> itemEntry = items.next();
    itemNames.add(itemEntry.getKey());
    itemDescriptions.add(itemEntry.getValue().get(DESCRIPTION_FIELD).asText());
    itemTypes.add(deserialize(itemEntry.getValue().get(TYPE_FIELD)));
  }
  final String[] EMPTY_STRING_ARRAY = new String[0];
  final OpenType<?>[] EMPTY_TYPE_ARRAY = new OpenType<?>[0];
  try {
    return new CompositeType(typeName,
        description,
        itemNames.toArray(EMPTY_STRING_ARRAY),
        itemDescriptions.toArray(EMPTY_STRING_ARRAY),
        itemTypes.toArray(EMPTY_TYPE_ARRAY));
  } catch (final OpenDataException e) {
    throw new OpenTypeProcessingException(e);
  }
}

代码示例来源:origin: io.sphere/sphere-java-client

/** Very simple way to "erase" passwords -
 *  replaces all field values whose names contains {@code 'pass'} by {@code 'xxxxx'}. */
private static JsonNode secure(JsonNode node) {
  if (node.isObject()) {
    ObjectNode objectNode = (ObjectNode)node;
    Iterator<Map.Entry<String, JsonNode>> fields = node.getFields();
    while (fields.hasNext()) {
      Map.Entry<String, JsonNode> field = fields.next();
      if (field.getValue().isTextual() && field.getKey().toLowerCase().contains("pass")) {
        objectNode.put(field.getKey(), "xxxxx");
      } else {
        secure(field.getValue());
      }
    }
    return objectNode;
  } else if (node.isArray()) {
    ArrayNode arrayNode = (ArrayNode)node;
    Iterator<JsonNode> elements = arrayNode.getElements();
    while (elements.hasNext()) {
      secure(elements.next());
    }
    return arrayNode;
  } else {
    return node;
  }
}

代码示例来源:origin: sirensolutions/siren

@Override
VariableQueryNode parse() throws ParseException {
 final VariableQueryNode queryNode = new VariableQueryNode();
 final JsonNode value = node.path(this.getProperty());
 if (value.getFields().hasNext()) {
   throw new ParseException("Node variable must contain an empty object as value.");
 }
 return queryNode;
}

代码示例来源:origin: org.eagle-i/eagle-i-datatools-catalyst

Iterator<Entry<String, JsonNode>> nodeIterator = node.getFields();
while( nodeIterator.hasNext() ) {
  Entry<String, JsonNode> oneEntry = nodeIterator.next();

代码示例来源:origin: gravel-st/gravel

private static Object jsonNodeAsSimpleObject(JsonNode value) {
  Object o = null;
  if (value.isTextual()) {
    o = value.asText();
  } else if (value.isArray()) {
    ArrayList<Object> arrayList = new ArrayList<>();
    for (Iterator<JsonNode> iter = ((ArrayNode) value).getElements(); iter
        .hasNext();) {
      arrayList.add(jsonNodeAsSimpleObject(iter.next()));
    }
    o = arrayList.toArray();
  } else if (value.isNull()) {
    o = null;
  } else if (value.isObject()) {
    HashMap<String, Object> map = new HashMap<String, Object>();
    final Iterator<Entry<String, JsonNode>> fields = value.getFields();
    while (fields.hasNext()) {
      final Entry<String, JsonNode> next = fields.next();
      map.put(next.getKey(), jsonNodeAsSimpleObject(next.getValue()));
    }
    o = map;
  } else
    throw new RuntimeException("Unknown type: " + value);
  return o;
}

代码示例来源:origin: com.googlecode.etl-unit/json-validator

private void readProperties(ObjectNode node) throws JsonSchemaValidationException {
  JsonNode propsNode = node.get("properties");
  if (propsNode == null)
  {
    return;
  }
  if (!propsNode.isObject())
  {
    throw new JsonSchemaValidationException("Invalid properties property - not object type", "", propsNode, null);
  }
  Iterator<Map.Entry<String,JsonNode>> fields = propsNode.getFields();
  while (fields.hasNext())
  {
    Map.Entry<String, JsonNode> field = fields.next();
    if (propertySchemas.containsKey(field.getKey()))
    {
      throw new JsonSchemaValidationException("Invalid properties property - property specified twice: " + field, "", propsNode, null);
    }
    JsonNode value = field.getValue();
    if (!value.isObject())
    {
      throw new JsonSchemaValidationException("Invalid properties property - value type not object: " + value, "", propsNode, null);
    }
    propertySchemas.put(field.getKey(), new JsonSchemaObjectNode((ObjectNode) value));
  }
}

相关文章