當前位置: 首頁>>代碼示例>>Java>>正文


Java JsonNode.isBoolean方法代碼示例

本文整理匯總了Java中com.fasterxml.jackson.databind.JsonNode.isBoolean方法的典型用法代碼示例。如果您正苦於以下問題:Java JsonNode.isBoolean方法的具體用法?Java JsonNode.isBoolean怎麽用?Java JsonNode.isBoolean使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.fasterxml.jackson.databind.JsonNode的用法示例。


在下文中一共展示了JsonNode.isBoolean方法的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: 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

示例3: assertFieldValue

import com.fasterxml.jackson.databind.JsonNode; //導入方法依賴的package包/類
/**
 * Asserts that the fieldName field in node have the expected value. 
 *
 * @param node the node
 * @param fieldName the field name
 * @param expected the expected
 */
private static void assertFieldValue(JsonNode node, String fieldName, Object expected) {
	JsonNode field = node.get(fieldName);
	assertNotNull(field);
	assertTrue(field.isValueNode());
	if (field.isNull()) {
		assertNull(expected);
	} else if (field.isTextual()) {
		assertEquals(expected, field.asText());
	} else if (field.isNumber()) {
		assertEquals(expected, field.numberValue());
	} else if (field.isBoolean()) {
		assertEquals(expected, field.asBoolean());
	} else {
		assertEquals(expected.toString(), field.toString());
	}
}
 
開發者ID:magrossi,項目名稱:es-log4j2-appender,代碼行數:24,代碼來源:ElasticSearchRestAppenderTest.java

示例4: parse

import com.fasterxml.jackson.databind.JsonNode; //導入方法依賴的package包/類
public static <T> Optional<T> parse(String fieldName, JsonNode node, Class<T> type) {
    JsonNode field = node.get(fieldName);
    T value = null;
    if (field != null && !field.isNull()) {
        if (type.equals(Long.class) && field.canConvertToLong()) {
            value = type.cast(field.asLong());
        }
        if (type.equals(Integer.class) && field.canConvertToInt()) {
            value = type.cast(field.asInt());
        }
        if (field.isTextual()) {
            value = type.cast(field.asText());
        }
        if (field.isDouble() || type.equals(Double.class)) {
            value = type.cast(field.asDouble());
        }
        if (field.isBoolean()) {
            value = type.cast(field.asBoolean());
        }
    }
    return Optional.ofNullable(value);
}
 
開發者ID:CSCfi,項目名稱:exam,代碼行數:23,代碼來源:SanitizingHelper.java

示例5: getElement

import com.fasterxml.jackson.databind.JsonNode; //導入方法依賴的package包/類
/**
 * Return the field with name in JSON as a string, a boolean, a number or a node.
 *
 * @param json json
 * @param name node name
 * @return the field
 */
public static Object getElement(final JsonNode json, final String name) {
    if (json != null && name != null) {
        JsonNode node = json;
        for (String nodeName : name.split("\\.")) {
            if (node != null) {
                node = node.get(nodeName);
            }
        }
        if (node != null) {
            if (node.isNumber()) {
                return node.numberValue();
            } else if (node.isBoolean()) {
                return node.booleanValue();
            } else if (node.isTextual()) {
                return node.textValue();
            } else if (node.isNull()) {
                return null;
            } else {
                return node;
            }
        }
    }
    return null;
}
 
開發者ID:yaochi,項目名稱:pac4j-plus,代碼行數:32,代碼來源:JsonHelper.java

示例6: isSetTo

import com.fasterxml.jackson.databind.JsonNode; //導入方法依賴的package包/類
default boolean isSetTo(String annotation, boolean testval) {
    JsonNode node = getAnnotations().get(annotation);
    if (node != null) {
        return node.isBoolean() && node.booleanValue() == testval;
    }
    return false;
}
 
開發者ID:atlascon,項目名稱:travny,代碼行數:8,代碼來源:Annotable.java

示例7: identifyPrimitiveMatch

import com.fasterxml.jackson.databind.JsonNode; //導入方法依賴的package包/類
private static UnionResolution identifyPrimitiveMatch(JsonNode datum, Set<Schema.Type> primitives) {
  // Try to identify specific primitive types
  Schema primitiveSchema = null;
  if (datum == null || datum.isNull()) {
    primitiveSchema = closestPrimitive(primitives, Schema.Type.NULL);
  } else if (datum.isShort() || datum.isInt()) {
    primitiveSchema = closestPrimitive(primitives, Schema.Type.INT, Schema.Type.LONG, Schema.Type.FLOAT,
        Schema.Type.DOUBLE);
  } else if (datum.isLong()) {
    primitiveSchema = closestPrimitive(primitives, Schema.Type.LONG, Schema.Type.DOUBLE);
  } else if (datum.isFloat()) {
    primitiveSchema = closestPrimitive(primitives, Schema.Type.FLOAT, Schema.Type.DOUBLE);
  } else if (datum.isDouble()) {
    primitiveSchema = closestPrimitive(primitives, Schema.Type.DOUBLE);
  } else if (datum.isBoolean()) {
    primitiveSchema = closestPrimitive(primitives, Schema.Type.BOOLEAN);
  }
  if (primitiveSchema == null
      && ((datum.isDouble() && datum.doubleValue() >= -Float.MAX_VALUE && datum.doubleValue() <= Float.MAX_VALUE)
          || (datum.isLong()
              && datum.longValue() >= (long) -Float.MAX_VALUE
              && datum.longValue() <= (long) Float.MAX_VALUE))) {
    primitiveSchema = closestPrimitive(primitives, Schema.Type.FLOAT, Schema.Type.DOUBLE);
  }

  if (primitiveSchema != null) {
    return new UnionResolution(primitiveSchema, MatchType.FULL);
  }
  return null;
}
 
開發者ID:HotelsDotCom,項目名稱:jasvorno,代碼行數:31,代碼來源:JasvornoConverter.java

示例8: matches

import com.fasterxml.jackson.databind.JsonNode; //導入方法依賴的package包/類
private MatchType matches(JsonNode datum, Schema schema) {
  switch (schema.getType()) {
  case RECORD:
    if (datum.isObject()) {
      return matchRecord(datum, schema);
    }
    break;
  case UNION:
    return resolveUnion(datum, schema.getTypes()).matchType;
  case MAP:
    if (datum.isObject()) {
      return matchMapValue(datum, schema);
    }
    break;
  case ARRAY:
    if (datum.isArray()) {
      return matchArrayElement(datum, schema);
    }
    break;
  case BOOLEAN:
    if (datum.isBoolean()) {
      return MatchType.FULL;
    }
    break;
  case FLOAT:
    if (datum.isDouble() && datum.doubleValue() >= -Float.MAX_VALUE && datum.doubleValue() <= Float.MAX_VALUE
        || datum.isLong()
            && datum.longValue() >= (long) -Float.MAX_VALUE
            && datum.longValue() <= (long) Float.MAX_VALUE
        || datum.isFloat()
        || datum.isInt()) {
      return MatchType.FULL;
    }
    break;
  case DOUBLE:
    if (datum.isDouble() || datum.isFloat() || datum.isLong() || datum.isInt()) {
      return MatchType.FULL;
    }
    break;
  case INT:
    if (datum.isInt()) {
      return MatchType.FULL;
    }
    break;
  case LONG:
    if (datum.isLong() || datum.isInt()) {
      return MatchType.FULL;
    }
    break;
  case STRING:
    if (datum.isTextual()) {
      return MatchType.FULL;
    }
    break;
  case ENUM:
    if (datum.isTextual() && schema.hasEnumSymbol(datum.textValue())) {
      return MatchType.FULL;
    }
    break;
  case BYTES:
  case FIXED:
    if (datum.isTextual()) {
      return MatchType.FULL;
    }
    break;
  case NULL:
    if (datum.isNull()) {
      return MatchType.FULL;
    }
    break;
  default: // unknown
    throw new IllegalArgumentException("Unsupported schema: " + schema);
  }
  return MatchType.NONE;
}
 
開發者ID:HotelsDotCom,項目名稱:jasvorno,代碼行數:76,代碼來源:JasvornoConverter.java

示例9: parse

import com.fasterxml.jackson.databind.JsonNode; //導入方法依賴的package包/類
@Override
public EnumNode parse(String nodeName, JsonNode jsonNode) {
    if (jsonNode == null) return null;
    JsonNode enumNode = jsonNode.get(JsonDataType.ENUM.getValue());
    if (enumNode == null) return null;

    Iterator<JsonNode> nodeIterator = enumNode.elements();
    while (nodeIterator.hasNext()) {
        JsonNode childNode = nodeIterator.next();
        if (isNullNode(childNode)) {
            // null is a valid value
            generator.addItem(null);
        } else {
            // Data type is unconstrained by the schema, but we only support primitive data types
            if (childNode.isInt()) {
                generator.addItem(childNode.intValue());
            } else if(childNode.isFloatingPointNumber()) {
                generator.addItem(childNode.doubleValue());
            } else if (childNode.isTextual()) {
                generator.addItem(childNode.textValue());
            } else if (childNode.isBoolean()) {
                generator.addItem(childNode.booleanValue());
            }
        }
    }
    return new EnumNode(nodeName, generator);
}
 
開發者ID:zezutom,項目名稱:schematic,代碼行數:28,代碼來源:EnumParser.java

示例10: parseProperty

import com.fasterxml.jackson.databind.JsonNode; //導入方法依賴的package包/類
@Override
void parseProperty(@NotNull ObjectGenerator generator, @NotNull JsonObjectProperty property, @NotNull JsonNode jsonNode) {
    switch (property) {
        case PROPERTIES:
            Iterator<String> fieldNameIterator = jsonNode.fieldNames();
            while (fieldNameIterator.hasNext()) {
                String fieldName = fieldNameIterator.next();
                generator.addProperty(fieldName, resolveGenerator(jsonNode.get(fieldName)));
            }
            break;
        case ADDITIONAL_PROPERTIES:
            if (jsonNode.isBoolean()) {
                generator.setAdditionalPropertiesAllowed(jsonNode.booleanValue());
            } else {
                JsonDataType dataType = JsonUtil.getDataType(jsonNode);
                if (dataType != null) {
                    JsonNodeParser parser = parserFactory.getInstance(jsonNode);
                    if (parser != null) {
                        Node node = parser.parse(jsonNode);
                        if (node != null) {
                            generator.addAdditionalGenerator(node.getValueGenerator());
                        }
                    }
                }
            }
            break;
        case MIN_PROPERTIES:
            generator.setMin(jsonNode.intValue());
            break;
        case MAX_PROPERTIES:
            generator.setMax(jsonNode.intValue());
            break;
        case REQUIRED:
            for (JsonNode requiredNode : jsonNode) {
                generator.addRequiredProperty(requiredNode.textValue());
            }
            break;
    }
}
 
開發者ID:zezutom,項目名稱:schematic,代碼行數:40,代碼來源:ObjectParser.java

示例11: fromJson

import com.fasterxml.jackson.databind.JsonNode; //導入方法依賴的package包/類
@Override
public Object fromJson(JsonNode json) {
	if (json.isTextual()) {
		return json.textValue();
	} else if (json.isNumber()) {
		return json.numberValue();
	} else if (json.isBoolean()) {
		return json.booleanValue();
	} else {
		return null;
	}
}
 
開發者ID:networknt,項目名稱:openapi-parser,代碼行數:13,代碼來源:PrimitiveOverlay.java

示例12: getValue

import com.fasterxml.jackson.databind.JsonNode; //導入方法依賴的package包/類
private Object getValue(JsonNode node) {
	if (node.isNumber()) {
		return node.numberValue();
	} else if (node.isTextual()) {
		return node.textValue();
	} else if (node.isBoolean()) {
		return node.booleanValue();
	} else if (node.isNull()) {
		return null;
	} else {
		throw new IllegalArgumentException("Non-value JSON node got through value node filter");
	}
}
 
開發者ID:networknt,項目名稱:openapi-parser,代碼行數:14,代碼來源:BigParseTest.java

示例13: evalObject

import com.fasterxml.jackson.databind.JsonNode; //導入方法依賴的package包/類
private void evalObject(ObjectNode source, ObjectNode target, RenderContext context,
	ScriptContext scriptContext)
{
	final Iterator<Entry<String, JsonNode>> it = source.fields();
	while( it.hasNext() )
	{
		final Entry<String, JsonNode> e = it.next();
		final String name = e.getKey();
		final JsonNode n = e.getValue();
		if( n.isObject() )
		{
			// recursively handle it
			final ObjectNode nt = jsonMapper.createObjectNode();
			target.put(name, nt);
			evalObject((ObjectNode) n, nt, context, scriptContext);
		}
		else if( n.isInt() || n.isLong() )
		{
			target.put(name, n.asInt());
		}
		else if( n.isFloatingPointNumber() || n.isDouble() )
		{
			target.put(name, n.asDouble());
		}
		else if( n.isBoolean() )
		{
			target.put(name, n.asBoolean());
		}
		else if( n.isArray() )
		{
			target.putArray(name).addAll((ArrayNode) n);
		}
		else
		{
			// freemarker eval
			target.put(name, evaluateMarkUp(context, n.asText(), scriptContext));
		}
	}
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:40,代碼來源:TinyMceAddonServiceImpl.java

示例14: JsonObjectExpression

import com.fasterxml.jackson.databind.JsonNode; //導入方法依賴的package包/類
protected JsonObjectExpression(ObjectNode o)
{
	super();
	final Iterator<Entry<String, JsonNode>> it = o.fields();
	while( it.hasNext() )
	{
		final Entry<String, JsonNode> e = it.next();
		final String name = e.getKey();
		final JsonNode n = e.getValue();
		if( n.isObject() )
		{
			put(name, new JsonObjectExpression((ObjectNode) n));
		}
		else if( n.isInt() )
		{
			put(name, n.asInt());
		}
		else if( n.isFloatingPointNumber() )
		{
			put(name, n.asDouble());
		}
		else if( n.isBoolean() )
		{
			put(name, n.asBoolean());
		}
		else
		{
			put(name, n.asText());
		}
	}
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:32,代碼來源:TinyMceAddonServiceImpl.java

示例15: decodeJson

import com.fasterxml.jackson.databind.JsonNode; //導入方法依賴的package包/類
private static Object decodeJson(String value) {
  int pos = 0;
  while (pos < value.length() && Character.isWhitespace(value.charAt(pos))) {
    pos++;
  }
  if (pos == value.length()) {
    return null;
  } else if (value.charAt(pos) == '{') {
    return new JsonObject(value);
  } else if (value.charAt(pos) == '[') {
    return new JsonArray(value);
  } else {
    try {
      JsonNode jsonNode = Json.mapper.readTree(value);
      if (jsonNode.isNumber()) {
        return jsonNode.numberValue();
      } else if (jsonNode.isBoolean()) {
        return jsonNode.booleanValue();
      } else if (jsonNode.isTextual()) {
        return jsonNode.textValue();
      }
    } catch (IOException e) {
      // do nothing
    }
  }
  return null;
}
 
開發者ID:vietj,項目名稱:reactive-pg-client,代碼行數:28,代碼來源:DataType.java


注:本文中的com.fasterxml.jackson.databind.JsonNode.isBoolean方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。