当前位置: 首页>>代码示例>>Java>>正文


Java JsonNode.fields方法代码示例

本文整理汇总了Java中com.fasterxml.jackson.databind.JsonNode.fields方法的典型用法代码示例。如果您正苦于以下问题:Java JsonNode.fields方法的具体用法?Java JsonNode.fields怎么用?Java JsonNode.fields使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.fasterxml.jackson.databind.JsonNode的用法示例。


在下文中一共展示了JsonNode.fields方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getKvEntries

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
public static List<KvEntry> getKvEntries(JsonNode data) {
  List<KvEntry> attributes = new ArrayList<>();
  for (Iterator<Map.Entry<String, JsonNode>> it = data.fields(); it.hasNext();) {
    Map.Entry<String, JsonNode> field = it.next();
    String key = field.getKey();
    JsonNode value = field.getValue();
    if (value.isBoolean()) {
      attributes.add(new BooleanDataEntry(key, value.asBoolean()));
    } else if (value.isLong()) {
      attributes.add(new LongDataEntry(key, value.asLong()));
    } else if (value.isDouble()) {
      attributes.add(new DoubleDataEntry(key, value.asDouble()));
    } else {
      attributes.add(new StringDataEntry(key, value.asText()));
    }
  }
  return attributes;
}
 
开发者ID:osswangxining,项目名称:iot-edge-greengrass,代码行数:19,代码来源:JsonTools.java

示例2: jsonNodeToTableUpdate

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
 * convert the params of Update Notification into TableUpdate.
 * @param tableSchema TableSchema entity
 * @param updateJson the table-update in params of Update Notification
 * @return TableUpdate
 */
public static TableUpdate jsonNodeToTableUpdate(TableSchema tableSchema, JsonNode updateJson) {
    Map<Uuid, RowUpdate> rows = Maps.newHashMap();
    Iterator<Map.Entry<String, JsonNode>> tableUpdateItr = updateJson.fields();
    while (tableUpdateItr.hasNext()) {
        Map.Entry<String, JsonNode> oldNewRow = tableUpdateItr.next();
        String uuidStr = oldNewRow.getKey();
        Uuid uuid = Uuid.uuid(uuidStr);
        JsonNode newR = oldNewRow.getValue().get("new");
        JsonNode oldR = oldNewRow.getValue().get("old");
        Row newRow = newR != null ? createRow(tableSchema, uuid, newR) : null;
        Row oldRow = oldR != null ? createRow(tableSchema, uuid, oldR) : null;
        RowUpdate rowUpdate = new RowUpdate(uuid, oldRow, newRow);
        rows.put(uuid, rowUpdate);
    }
    return TableUpdate.tableUpdate(rows);
}
 
开发者ID:shlee89,项目名称:athena,代码行数:23,代码来源:FromJsonUtil.java

示例3: createRow

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
/**
 * Convert Operation JsonNode into Row.
 * @param tableSchema TableSchema entity
 * @param rowNode JsonNode
 * @return Row
 */
private static Row createRow(TableSchema tableSchema, Uuid uuid, JsonNode rowNode) {
    if (tableSchema == null) {
        return null;
    }
    Map<String, Column> columns = Maps.newHashMap();
    Iterator<Map.Entry<String, JsonNode>> rowIter = rowNode.fields();
    while (rowIter.hasNext()) {
        Map.Entry<String, JsonNode> next = rowIter.next();
        ColumnSchema columnSchema = tableSchema.getColumnSchema(next.getKey());
        if (columnSchema != null) {
            String columnName = columnSchema.name();
            Object obj = TransValueUtil.getValueFromJson(next.getValue(), columnSchema.type());
            columns.put(columnName, new Column(columnName, obj));
        }
    }
    return new Row(tableSchema.name(), uuid, columns);
}
 
开发者ID:shlee89,项目名称:athena,代码行数:24,代码来源:FromJsonUtil.java

示例4: getKvEntries

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
public static List<KvEntry> getKvEntries(JsonNode data) {
    List<KvEntry> attributes = new ArrayList<>();
    for (Iterator<Map.Entry<String, JsonNode>> it = data.fields(); it.hasNext(); ) {
        Map.Entry<String, JsonNode> field = it.next();
        String key = field.getKey();
        JsonNode value = field.getValue();
        if (value.isBoolean()) {
            attributes.add(new BooleanDataEntry(key, value.asBoolean()));
        } else if (value.isLong()) {
            attributes.add(new LongDataEntry(key, value.asLong()));
        } else if (value.isDouble()) {
            attributes.add(new DoubleDataEntry(key, value.asDouble()));
        } else {
            attributes.add(new StringDataEntry(key, value.asText()));
        }
    }
    return attributes;
}
 
开发者ID:thingsboard,项目名称:thingsboard-gateway,代码行数:19,代码来源:JsonTools.java

示例5: getTaskFromJson

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private Task getTaskFromJson(JsonNode node) throws JsonProcessingException {
	if (node.isObject()) {
		ObjectNode onode = (ObjectNode) node;
		final JsonNode type = onode.remove("type");
		final JsonNode attributes = onode.remove("attributes");
		final JsonNode relationships = onode.remove("relationships");
		final JsonNode links = onode.remove("links");
		Iterator<Map.Entry<String, JsonNode>> fields = attributes.fields();
		while (fields.hasNext()) {
			Map.Entry<String, JsonNode> f = fields.next();
			onode.put(f.getKey(), f.getValue().textValue());
		}
		return mapper.treeToValue(onode, Task.class);
	}
	else {
		throw new JsonMappingException("Not an object: " + node);
	}
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:19,代码来源:JerseyApplicationTest.java

示例6: calculateDict

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
public static int calculateDict(JsonNode node) {
    int count = 0;
    Iterator<Map.Entry<String, JsonNode>> iterator = node.fields();
    while (iterator.hasNext())
    {
        Map.Entry<String,JsonNode> element = iterator.next();
        if (element.getValue().isArray()) {
            if (element.getKey().toLowerCase() == "fields")
            {
                count += element.getValue().size();
            }
            count += calculateList(element.getValue());
        } else if (element.getValue().isContainerNode()) {
            if (element.getKey().toLowerCase() == "fields")
            {
                count += element.getValue().size();
            }
            count += calculateDict(element.getValue());
        }
        else if (element.getKey().toLowerCase() == "fields")
        {
            count += 1;
        }
    }
    return count;
}
 
开发者ID:thomas-young-2013,项目名称:wherehowsX,代码行数:27,代码来源:SchemaHistory.java

示例7: readMap

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@Override
protected Map readMap(MapSchema schema, JsonNode node) {
    Preconditions.checkNotNull(schema);
    Preconditions.checkNotNull(node);
    if (node instanceof ArrayNode) {
        return super.readMap(schema, node);
    }
    Preconditions.checkArgument(node instanceof ObjectNode);
    Schema keySchema = schema.getKeySchema();
    switch (keySchema.getType()) {
        case RECORD:
        case MAP:
        case LIST:
            return super.readMap(schema, node);
    }
    Map map = Maps.newLinkedHashMap();
    Iterator<Map.Entry<String, JsonNode>> fields = node.fields();
    while (fields.hasNext()) {
        Map.Entry<String, JsonNode> field = fields.next();
        String key = field.getKey();
        JsonNode val = field.getValue();
        map.put(keyFromString(schema.getKeySchema(), key), getNodeData(schema.getValueSchema(), val));
    }
    return map;
}
 
开发者ID:atlascon,项目名称:travny,代码行数:26,代码来源:SimpleJsonReader.java

示例8: deserialize

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@Override
public ApiReturnModel deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {

    JsonNode node = jp.getCodec().readTree(jp);
    List<ApiReturnItem> outputTemp = new ArrayList<>();

    Iterator<Map.Entry<String, JsonNode>> fields = node.fields();

    while (fields.hasNext()){
        Map.Entry<String, JsonNode> curr = fields.next();
        ApiReturnItem item = new ApiReturnItem();

        item.mainTerm = curr.getKey();

        JsonNode stringlist = curr.getValue().get(0);
        item.similarTerms = new String[stringlist.size()];
        for (int i = 0; i < stringlist.size();i++) {
            item.similarTerms[i] = stringlist.get(i).asText();
        }

        JsonNode weightlist = curr.getValue().get(1);
        item.similarWeights = new float[weightlist.size()];
        for (int i = 0; i < weightlist.size();i++) {
            item.similarWeights[i] = weightlist.get(i).floatValue();
        }

        outputTemp.add(item);
    }

    return new ApiReturnModel(outputTemp.toArray(new ApiReturnItem[0]));
}
 
开发者ID:sebastian-hofstaetter,项目名称:ir-generalized-translation-models,代码行数:33,代码来源:ItemDeserializer.java

示例9: addInternalSetMethodJava7

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private JMethod addInternalSetMethodJava7(JDefinedClass jclass, JsonNode propertiesNode) {
    JMethod method = jclass.method(PROTECTED, jclass.owner().BOOLEAN, DEFINED_SETTER_NAME);
    JVar nameParam = method.param(String.class, "name");
    JVar valueParam = method.param(Object.class, "value");
    JBlock body = method.body();
    JSwitch propertySwitch = body._switch(nameParam);
    if (propertiesNode != null) {
        for (Iterator<Map.Entry<String, JsonNode>> properties = propertiesNode.fields(); properties.hasNext();) {
            Map.Entry<String, JsonNode> property = properties.next();
            String propertyName = property.getKey();
            JsonNode node = property.getValue();
            String fieldName = ruleFactory.getNameHelper().getPropertyName(propertyName, node);
            JType propertyType = jclass.fields().get(fieldName).type();

            addSetPropertyCase(jclass, propertySwitch, propertyName, propertyType, valueParam, node);
        }
    }
    JBlock defaultBlock = propertySwitch._default().body();
    JClass extendsType = jclass._extends();
    if (extendsType != null && extendsType instanceof JDefinedClass) {
        JDefinedClass parentClass = (JDefinedClass) extendsType;
        JMethod parentMethod = parentClass.getMethod(DEFINED_SETTER_NAME,
                new JType[] { parentClass.owner()._ref(String.class), parentClass.owner()._ref(Object.class) });
        defaultBlock._return(_super().invoke(parentMethod).arg(nameParam).arg(valueParam));
    } else {
        defaultBlock._return(FALSE);
    }
    return method;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:30,代码来源:DynamicPropertiesRule.java

示例10: addInternalSetMethodJava6

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private JMethod addInternalSetMethodJava6(JDefinedClass jclass, JsonNode propertiesNode) {
    JMethod method = jclass.method(PROTECTED, jclass.owner().BOOLEAN, DEFINED_SETTER_NAME);
    JVar nameParam = method.param(String.class, "name");
    JVar valueParam = method.param(Object.class, "value");
    JBlock body = method.body();
    JConditional propertyConditional = null;
    if (propertiesNode != null) {
        for (Iterator<Map.Entry<String, JsonNode>> properties = propertiesNode.fields(); properties.hasNext();) {
            Map.Entry<String, JsonNode> property = properties.next();
            String propertyName = property.getKey();
            JsonNode node = property.getValue();
            String fieldName = ruleFactory.getNameHelper().getPropertyName(propertyName, node);
            JType propertyType = jclass.fields().get(fieldName).type();
            JExpression condition = lit(propertyName).invoke("equals").arg(nameParam);
            propertyConditional = propertyConditional == null ? propertyConditional = body._if(condition)
                    : propertyConditional._elseif(condition);

            JBlock callSite = propertyConditional._then();
            addSetProperty(jclass, callSite, propertyName, propertyType, valueParam, node);
            callSite._return(TRUE);
        }
    }
    JClass extendsType = jclass._extends();
    JBlock lastBlock = propertyConditional == null ? body : propertyConditional._else();

    if (extendsType != null && extendsType instanceof JDefinedClass) {
        JDefinedClass parentClass = (JDefinedClass) extendsType;
        JMethod parentMethod = parentClass.getMethod(DEFINED_SETTER_NAME,
                new JType[] { parentClass.owner()._ref(String.class), parentClass.owner()._ref(Object.class) });
        lastBlock._return(_super().invoke(parentMethod).arg(nameParam).arg(valueParam));
    } else {
        lastBlock._return(FALSE);
    }
    return method;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:36,代码来源:DynamicPropertiesRule.java

示例11: editProps

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
public static String editProps(String ogPropString, String ygPropString) throws IOException {
  JsonNode ogPropNode = Json.parse(ogPropString);
  JsonNode ygPropNode = Json.parse(ygPropString);

  Iterator<Map.Entry<String, JsonNode>> ygPropIter = ygPropNode.fields();

  while (ygPropIter.hasNext()) {
    Entry<String,JsonNode> field = ygPropIter.next();
    if (field.getKey() != "urn") {
      ((ObjectNode) ogPropNode).put(field.getKey(), field.getValue());
    }
  }
  return ogPropNode.toString();
}
 
开发者ID:SirAeroWN,项目名称:premier-wherehows,代码行数:15,代码来源:DatasetDao.java

示例12: getSTOCHRSI

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@Override
public LinkedHashMap<LocalDate, StochfIndicator> getSTOCHRSI(String symbol, TimeInterval interval, String timePeriod, SeriesType seriesType, HashMap<String, String> options) {
    String queryString = ALPHA_VANTAGE_API_URL + "function=STOCHRSI&symbol=" + symbol + "&time_period=" + timePeriod + "&series_type=" + seriesType + "&interval=" + interval.getName() + "&apikey=" + apiKey + "&";
    String encodedUrl = options.keySet().stream().map(key -> {
        try {
            return key + "=" + UriUtils.encode(options.get(key), "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return null;
    }).collect(joining("&", queryString, ""));


    LinkedHashMap<LocalDate, StochfIndicator> result = new LinkedHashMap<>();
    JsonNode jsonNode = restTemplate.getForObject(encodedUrl, JsonNode.class);
    Iterator<Map.Entry<String, JsonNode>> it = jsonNode.fields();
    while (it.hasNext()) {
        Map.Entry<String, JsonNode> mapEntry = it.next();
        if (mapEntry.getKey().equals("Technical Analysis: STOCHRSI")) {
            JsonNode node = mapEntry.getValue();
            Iterator<Map.Entry<String, JsonNode>> timeSeriesIter = node.fields();
            while (timeSeriesIter.hasNext()) {
                Map.Entry<String, JsonNode> timeSeriesMap = timeSeriesIter.next();
                LocalDate localDate = LocalDate.parse(timeSeriesMap.getKey(), DateTimeFormatter.ISO_LOCAL_DATE);
                String fastK = String.valueOf(timeSeriesMap.getValue().get("FastK"));
                String fastD = String.valueOf(timeSeriesMap.getValue().get("FastD"));
                result.put(localDate, StochfIndicator.newInstance(symbol, fastK, fastD));
            }

        }
    }

    return result;
}
 
开发者ID:cautiontowind,项目名称:alpha-vantage,代码行数:35,代码来源:TechnicalIndicatorTemplate.java

示例13: requestApiData

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private LinkedHashMap<LocalDate, DigitalCurrency> requestApiData(String function, DigitalCurrencyType symbol, MarketList market) throws UnsupportedEncodingException, InvalidApiKeyException, InvalidFunctionOptionException, MalFormattedFunctionException, MissingApiKeyException, UltraHighFrequencyRequestException {
    String queryString = ALPHA_VANTAGE_API_URL + "function=" + function + "&symbol=" + String.valueOf(symbol).replace("_", "") + "&market=" + market.toString() + "&apikey=" + apiKey + "&";
    JsonNode jsonNode = restTemplate.getForObject(queryString, JsonNode.class);
    Iterator<Map.Entry<String, JsonNode>> it = jsonNode.fields();

    LinkedHashMap<LocalDate, DigitalCurrency> result = new LinkedHashMap<>();

    while (it.hasNext()) {
        Map.Entry<String, JsonNode> mapEntry = it.next();
        ExceptionUtil.handleException(mapEntry, function);
        String duration = function.substring(17).toLowerCase();
        String titleCase = String.valueOf(duration.charAt(0)).toUpperCase() + duration.substring(1);
        if (mapEntry.getKey().equals("Time Series (Digital Currency " + titleCase + ")")) {
            JsonNode node = mapEntry.getValue();
            Iterator<Map.Entry<String, JsonNode>> timeSeriesIter = node.fields();
            while (timeSeriesIter.hasNext()) {
                Map.Entry<String, JsonNode> timeSeriesMap = timeSeriesIter.next();
                LocalDate localDate = LocalDate.parse(timeSeriesMap.getKey(), DateTimeFormatter.ISO_LOCAL_DATE);
                String openA = String.valueOf(timeSeriesMap.getValue().get("1a. open (" + market + ")")).replaceAll("\"", "");
                String openB = String.valueOf(timeSeriesMap.getValue().get("1b. open (USD)")).replaceAll("\"", "");

                String highA = String.valueOf(timeSeriesMap.getValue().get("2a. high (" + market + ")")).replaceAll("\"", "");
                String highB = String.valueOf(timeSeriesMap.getValue().get("2b. high (USD)")).replaceAll("\"", "");

                String lowA = String.valueOf(timeSeriesMap.getValue().get("3a. low (" + market + ")")).replaceAll("\"", "");
                String lowB = String.valueOf(timeSeriesMap.getValue().get("3b. low (USD)")).replaceAll("\"", "");

                String closeA = String.valueOf(timeSeriesMap.getValue().get("4a. close (" + market + ")")).replaceAll("\"", "");
                String closeB = String.valueOf(timeSeriesMap.getValue().get("4b. close (USD)")).replaceAll("\"", "");

                String volA = String.valueOf(timeSeriesMap.getValue().get("5a. volume (" + market + ")")).replaceAll("\"", "");
                String volB = String.valueOf(timeSeriesMap.getValue().get("5b. volume (USD)")).replaceAll("\"", "");
                result.put(localDate, DigitalCurrencyDaily.newInstance(symbol.name(), market.name(), openA, highA, lowA, closeA, volA, openB, highB, lowB, closeB, volB));
            }

        }
    }

    return result;
}
 
开发者ID:cautiontowind,项目名称:alpha-vantage,代码行数:41,代码来源:CryptoCurrencyTemplate.java

示例14: getEnvironmentV1

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
public Environment getEnvironmentV1(Application app) {

		String url = app.endpoints().env();

		try {
			LOGGER.debug("GET {}", url);
			ResponseEntity<String> response = restTemplates.get(app).getForEntity(url, String.class);

			String json = response.getBody();

			ObjectMapper mapper = new ObjectMapper();
			mapper.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, false);
			JsonNode rootNode = mapper.readTree(json);

			List<PropertyItem> properties = new ArrayList<>();

			Iterator<Entry<String, JsonNode>> iterator = rootNode.fields();

			// Get properties
			while (iterator.hasNext()) {
				Entry<String, JsonNode> current = iterator.next();

				current.getValue().fields().forEachRemaining(
						// current.getKey ==> origin of the property : system,
						// application.properties, etc
						p -> properties.add(new PropertyItem(p.getKey(), p.getValue().asText(), current.getKey())));
			}

			return new Environment(properties);
		} catch (RestClientException ex) {
			throw RestTemplateErrorHandler.handle(app, url, ex);
		} catch (IOException e) {
			throw RestTemplateErrorHandler.handle(app, e);
		}
	}
 
开发者ID:vianneyfaivre,项目名称:Persephone,代码行数:36,代码来源:EnvironmentService.java

示例15: loadDocument

import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private Document loadDocument(JsonNode node) {
    Map<String, Object> objectMap = new LinkedHashMap<>();
    Iterator<Map.Entry<String, JsonNode>> fields = node.fields();
    while (fields.hasNext()) {
        Map.Entry<String, JsonNode> entry = fields.next();
        String name = entry.getKey();
        JsonNode value = entry.getValue();
        Object object = loadObject(value);
        objectMap.put(name, object);
    }

    return new Document(objectMap);
}
 
开发者ID:dizitart,项目名称:nitrite-database,代码行数:14,代码来源:JacksonMapper.java


注:本文中的com.fasterxml.jackson.databind.JsonNode.fields方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。