本文整理了Java中com.fasterxml.jackson.databind.JsonNode.size()
方法的一些代码示例,展示了JsonNode.size()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonNode.size()
方法的具体详情如下:
包路径:com.fasterxml.jackson.databind.JsonNode
类名称:JsonNode
方法名:size
[英]Method that returns number of child nodes this node contains: for Array nodes, number of child elements, for Object nodes, number of fields, and for all other nodes 0.
[中]方法返回此节点包含的子节点数:对于数组节点,子元素数,对象节点,字段数,以及所有其他节点0。
代码示例来源:origin: apache/incubator-pinot
private static List<Object> jsonArrayToList(JsonNode jsonArray) {
List<Object> list = new ArrayList<>();
for (int i = 0; i < jsonArray.size(); ++i) {
list.add(jsonArray.get(i));
}
return list;
}
代码示例来源:origin: joelittlejohn/jsonschema2pojo
private String getTypeName(JsonNode node) {
if (node.has("type") && node.get("type").isArray() && node.get("type").size() > 0) {
for (JsonNode jsonNode : node.get("type")) {
String typeName = jsonNode.asText();
if (!typeName.equals("null")) {
return typeName;
}
}
}
if (node.has("type") && node.get("type").isTextual()) {
return node.get("type").asText();
}
return DEFAULT_TYPE_NAME;
}
代码示例来源: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: apache/incubator-druid
if (node.isArray()) {
final List<Object> nodeValue = Lists.newArrayListWithExpectedSize(node.size());
for (final JsonNode subnode : node) {
final Object subnodeValue = valueFunction.apply(subnode);
if (subnodeValue != null) {
nodeValue.add(subnodeValue);
代码示例来源:origin: Graylog2/graylog2-server
public static ElasticsearchException specificException(Supplier<String> errorMessage, JsonNode errorNode) {
final JsonNode rootCauses = errorNode.path("root_cause");
final List<String> reasons = new ArrayList<>(rootCauses.size());
reasons.add(reason.asText());
continue;
switch(type.asText()) {
case "query_parsing_exception":
return buildQueryParsingException(errorMessage, rootCause, reasons);
case "index_not_found_exception":
final String indexName = rootCause.path("resource.id").asText();
return buildIndexNotFoundException(errorMessage, indexName);
case "illegal_argument_exception":
代码示例来源:origin: testcontainers/testcontainers-java
private AuthConfig authConfigUsingHelper(final JsonNode config, final String reposName) throws Exception {
final JsonNode credHelpers = config.get("credHelpers");
if (credHelpers != null && credHelpers.size() > 0) {
final JsonNode helperNode = credHelpers.get(reposName);
if (helperNode != null && helperNode.isTextual()) {
final String helper = helperNode.asText();
return runCredentialProvider(reposName, helper);
}
}
return null;
}
代码示例来源:origin: auth0/java-jwt
@Override
@SuppressWarnings("unchecked")
public <T> T[] asArray(Class<T> tClazz) throws JWTDecodeException {
if (!data.isArray()) {
return null;
}
T[] arr = (T[]) Array.newInstance(tClazz, data.size());
for (int i = 0; i < data.size(); i++) {
try {
arr[i] = objectReader.treeToValue(data.get(i), tClazz);
} catch (JsonProcessingException e) {
throw new JWTDecodeException("Couldn't map the Claim's array contents to " + tClazz.getSimpleName(), e);
}
}
return arr;
}
代码示例来源:origin: graphhopper/graphhopper
@Override
public PathDetail deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
JsonNode pathDetail = jp.readValueAsTree();
if (pathDetail.size() != 3)
throw new JsonParseException(jp, "PathDetail array must have exactly 3 entries but was " + pathDetail.size());
JsonNode from = pathDetail.get(0);
JsonNode to = pathDetail.get(1);
JsonNode val = pathDetail.get(2);
PathDetail pd;
if (val.isBoolean())
pd = new PathDetail(val.asBoolean());
else if (val.isLong())
pd = new PathDetail(val.asLong());
else if (val.isInt())
pd = new PathDetail(val.asInt());
else if (val.isDouble())
pd = new PathDetail(val.asDouble());
else if (val.isTextual())
pd = new PathDetail(val.asText());
else
throw new JsonParseException(jp, "Unsupported type of PathDetail value " + pathDetail.getNodeType().name());
pd.setFirst(from.asInt());
pd.setLast(to.asInt());
return pd;
}
}
代码示例来源: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: liferay/liferay-portal
/**
* Returns the exposed entry points in a Map. The key is the ID of a given
* resource collection and the value its managed type
*
* @return Map<String, String> Resource ID / Managed type, empty otherwise
*/
public Map<String, String> getRootEndpointMap() {
JsonNode collectionArrayJsonNode = getCollectionJsonNode();
if (!collectionArrayJsonNode.isArray() ||
(collectionArrayJsonNode.size() == 0)) {
if (_log.isDebugEnabled()) {
_log.debug(
"Unable to fetch the resources from the entry point");
}
return Collections.emptyMap();
}
Map<String, String> rootEndpointMap = new TreeMap<>();
for (final JsonNode collectionJsonNode : collectionArrayJsonNode) {
JsonNode idJsonNode = collectionJsonNode.path(JSONLDConstants.ID);
String managedType = ApioUtils.getManagedType(collectionJsonNode);
rootEndpointMap.put(idJsonNode.asText(), managedType);
}
return Collections.unmodifiableMap(rootEndpointMap);
}
代码示例来源:origin: liferay/liferay-portal
protected JsonNode findJsonNode(JsonNode resource, String nodeName) {
JsonNode jsonNode = resource.path(nodeName);
if (_log.isDebugEnabled()) {
if (jsonNode.isMissingNode()) {
_log.debug("Unable to find the \"{}\" node", nodeName);
}
if (jsonNode.isArray() && (jsonNode.size() == 0)) {
_log.debug("The \"{}\" array node is empty", jsonNode);
}
}
return jsonNode;
}
代码示例来源:origin: Activiti/Activiti
protected List<String> getActiveValueList(List<String> originalValues, String propertyName, ObjectNode taskElementProperties) {
List<String> activeValues = originalValues;
if (taskElementProperties != null) {
JsonNode overrideValuesNode = taskElementProperties.get(propertyName);
if (overrideValuesNode != null) {
if (overrideValuesNode.isNull() || !overrideValuesNode.isArray() || overrideValuesNode.size() == 0) {
activeValues = null;
} else {
activeValues = new ArrayList<String>();
for (JsonNode valueNode : overrideValuesNode) {
activeValues.add(valueNode.asText());
}
}
}
}
return activeValues;
}
}
代码示例来源:origin: aws/aws-sdk-java
private static List<JmesPathExpression> getChildren(JsonNode jsonNode){
if(jsonNode.get("children").size() < 1) {
throw new RuntimeException("Expected one or more arguments");
}
Iterator<JsonNode> children = jsonNode.get("children").elements();
final List<JmesPathExpression> childrenList = new ArrayList<>();
while (children.hasNext()) {
childrenList.add(fromAstJsonToAstJava(children.next()));
}
return childrenList;
}
代码示例来源:origin: apache/incubator-pinot
private static String serializeRow(JsonNode row, Map<Integer, Integer> expectedToActualColMap) {
StringBuilder sb = new StringBuilder();
final int numCols = row.size();
sb.append(numCols).append('_');
for (int i = 0; i < numCols; i++) {
String toAppend;
if (expectedToActualColMap == null) {
toAppend = row.get(i).asText();
} else {
toAppend = row.get(expectedToActualColMap.get(i)).asText();
}
// For number value, uniform the format and do fuzzy comparison
try {
double numValue = Double.parseDouble(toAppend);
sb.append((int) (numValue * 100)).append('_');
} catch (NumberFormatException e) {
sb.append(toAppend).append('_');
}
}
return sb.toString();
}
代码示例来源:origin: liferay/liferay-portal
public JsonNode getFirstEntryJsonNode() {
JsonNode memberJsonNode = getMemberJsonNode();
if (!memberJsonNode.isArray() || (memberJsonNode.size() == 0)) {
if (_log.isDebugEnabled()) {
_log.debug("Unable to fetch the member node");
}
return MissingNode.getInstance();
}
return memberJsonNode.get(0);
}
代码示例来源:origin: joelittlejohn/jsonschema2pojo
private ObjectNode arraySchema(JsonNode exampleArray) {
ObjectNode schema = this.objectMapper.createObjectNode();
schema.put("type", "array");
if (exampleArray.size() > 0) {
JsonNode exampleItem = exampleArray.get(0).isObject() ? mergeArrayItems(exampleArray) : exampleArray.get(0);
schema.set("items", schemaFromExample(exampleItem));
}
return schema;
}
代码示例来源:origin: joelittlejohn/jsonschema2pojo
private void addEnumConstants(JsonNode node, JDefinedClass _enum, JsonNode customNames, JType type) {
Collection<String> existingConstantNames = new ArrayList<>();
for (int i = 0; i < node.size(); i++) {
JsonNode value = node.path(i);
if (!value.isNull()) {
String constantName = getConstantName(value.asText(), customNames.path(i).asText());
constantName = makeUnique(constantName, existingConstantNames);
existingConstantNames.add(constantName);
JEnumConstant constant = _enum.enumConstant(constantName);
constant.arg(DefaultRule.getDefaultValue(type, value));
ruleFactory.getAnnotator().enumConstant(_enum, constant, value.asText());
}
}
}
代码示例来源:origin: liferay/liferay-portal
private static JsonNode _findJsonNode(JsonNode resource, String nodeName) {
JsonNode jsonNode = resource.path(nodeName);
if (_log.isDebugEnabled()) {
if (jsonNode.isMissingNode()) {
_log.debug("Unable to find the \"{}\" node", nodeName);
}
if (jsonNode.isArray() && (jsonNode.size() == 0)) {
_log.debug("The \"{}\" array node is empty", jsonNode);
}
}
return jsonNode;
}
代码示例来源:origin: auth0/java-jwt
List<String> getStringOrArray(Map<String, JsonNode> tree, String claimName) throws JWTDecodeException {
JsonNode node = tree.get(claimName);
if (node == null || node.isNull() || !(node.isArray() || node.isTextual())) {
return null;
}
if (node.isTextual() && !node.asText().isEmpty()) {
return Collections.singletonList(node.asText());
}
List<String> list = new ArrayList<>(node.size());
for (int i = 0; i < node.size(); i++) {
try {
list.add(objectReader.treeToValue(node.get(i), String.class));
} catch (JsonProcessingException e) {
throw new JWTDecodeException("Couldn't map the Claim's array contents to String", e);
}
}
return list;
}
代码示例来源:origin: twosigma/beakerx
@Override
public Object deserialize(JsonNode n, ObjectMapper mapper) {
List<Object> o = new ArrayList<Object>();
try {
logger.debug("using custom array deserializer");
for(int i=0; i<n.size(); i++) {
o.add(parent.deserialize(n.get(i), mapper));
}
} catch (Exception e) {
logger.error("exception deserializing Collection ", e);
o = null;
}
return o;
}
内容来源于网络,如有侵权,请联系作者删除!