本文整理了Java中com.fasterxml.jackson.databind.JsonNode.getNodeType()
方法的一些代码示例,展示了JsonNode.getNodeType()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonNode.getNodeType()
方法的具体详情如下:
包路径:com.fasterxml.jackson.databind.JsonNode
类名称:JsonNode
方法名:getNodeType
[英]Return the type of this node
[中]返回此节点的类型
代码示例来源:origin: redisson/redisson
@Override
public final boolean isContainerNode() {
final JsonNodeType type = getNodeType();
return type == JsonNodeType.OBJECT || type == JsonNodeType.ARRAY;
}
代码示例来源:origin: redisson/redisson
/**
* Method that can be used to check if this node was created from
* JSON literal null value.
*/
public final boolean isNull() {
return getNodeType() == JsonNodeType.NULL;
}
代码示例来源:origin: redisson/redisson
@Override
public final boolean isValueNode()
{
switch (getNodeType()) {
case ARRAY: case OBJECT: case MISSING:
return false;
default:
return true;
}
}
代码示例来源:origin: redisson/redisson
/**
* @return True if this node represents a numeric JSON value
*/
public final boolean isNumber() {
return getNodeType() == JsonNodeType.NUMBER;
}
代码示例来源:origin: redisson/redisson
/**
* Method that can be used to check if this node was created from
* JSON boolean value (literals "true" and "false").
*/
public final boolean isBoolean() {
return getNodeType() == JsonNodeType.BOOLEAN;
}
代码示例来源:origin: redisson/redisson
/**
* Method that can be used to check if this node represents
* binary data (Base64 encoded). Although this will be externally
* written as JSON String value, {@link #isTextual} will
* return false if this method returns true.
*
* @return True if this node represents base64 encoded binary data
*/
public final boolean isBinary() {
return getNodeType() == JsonNodeType.BINARY;
}
代码示例来源:origin: redisson/redisson
/**
* Method that can be used to check if the node is a wrapper
* for a POJO ("Plain Old Java Object" aka "bean".
* Returns true only for
* instances of <code>POJONode</code>.
*
* @return True if this node wraps a POJO
*/
public final boolean isPojo() {
return getNodeType() == JsonNodeType.POJO;
}
代码示例来源:origin: redisson/redisson
/**
* Method that checks whether this node represents basic JSON String
* value.
*/
public final boolean isTextual() {
return getNodeType() == JsonNodeType.STRING;
}
代码示例来源:origin: apache/kafka
private static Object convert(JsonNode value) {
if (value.isArray()) {
List<String> retvalList = new ArrayList<>();
for (JsonNode arrayElement : value)
retvalList.add(arrayElement.asText());
return retvalList;
}
return value.getNodeType() == JsonNodeType.NUMBER ? value.numberValue() : value.asText();
}
代码示例来源:origin: bootique/bootique
protected static ObjectNode toObjectNode(JsonNode node) {
if (node != null) {
if (node.isNull()) {
return null;
}
if (!(node instanceof ObjectNode)) {
throw new IllegalArgumentException(
"Expected OBJECT node. Instead got " + node.getNodeType());
}
}
return (ObjectNode) node;
}
代码示例来源:origin: bootique/bootique
protected static ArrayNode toArrayNode(JsonNode node) {
if (node != null) {
if (node.isNull()) {
return null;
}
if (!(node instanceof ArrayNode)) {
throw new IllegalArgumentException(
"Expected ARRAY node. Instead got " + node.getNodeType());
}
}
return (ArrayNode) node;
}
代码示例来源:origin: aws/aws-sdk-java
/**
* Get a textual value from a json object, throwing an exception if the node is missing or not textual.
*/
private String getText(JsonNode jsonObject, String nodeName) {
JsonNode subNode = jsonObject.get(nodeName);
if (subNode == null) {
return null;
}
if (!subNode.isTextual()) {
throw new IllegalStateException(nodeName + " from credential process should be textual, but was " +
subNode.getNodeType());
}
return subNode.asText();
}
代码示例来源:origin: stagemonitor/stagemonitor
private static <T extends JsonNode> T tryDecode(JsonNode encodedNode, T defaultValue, String fieldName) throws IOException {
if (encodedNode == null || encodedNode.isNull()) {
return defaultValue;
}
if (!encodedNode.isTextual()) {
throw new IllegalArgumentException("error before decoding " + fieldName + "." +
" Expected textual or null field, but encountered " + encodedNode.getNodeType());
}
JsonNode decodedNode = mapper.readTree(encodedNode.textValue());
if (!decodedNode.getNodeType().equals(defaultValue.getNodeType())) {
throw new IllegalArgumentException("error after decoding" + fieldName + "." +
" Expected decoded type to be " + defaultValue.getNodeType() + ", but encountered " + decodedNode.getNodeType());
}
return (T) decodedNode;
}
代码示例来源:origin: line/armeria
private static void addHeader(DeserializationContext ctx, HttpHeaders headers,
AsciiString name, JsonNode valueNode) throws JsonMappingException {
if (!valueNode.isTextual()) {
ctx.reportInputMismatch(HttpHeaders.class,
"HTTP header '%s' contains %s (%s); only strings are allowed.",
name, valueNode.getNodeType(), valueNode);
}
headers.add(name, valueNode.asText());
}
}
代码示例来源:origin: Graylog2/graylog2-server
log.warn(prefix + "has invalid \"timestamp\": {} (type: {})", timestampNode.asText(), timestampNode.getNodeType().name());
代码示例来源:origin: Graylog2/graylog2-server
switch (read.getNodeType()) {
case ARRAY:
return ImmutableList.copyOf(read.elements());
代码示例来源:origin: Graylog2/graylog2-server
if (versionNode.getNodeType() != JsonNodeType.MISSING) {
clusterVersion = versionNode.asText();
代码示例来源:origin: auth0/java-jwt
@Test
public void shouldThrowIfAnExtraordinaryExceptionHappensWhenParsingAsGenericMap() throws Exception {
JsonNode value = mock(ObjectNode.class);
when(value.getNodeType()).thenReturn(JsonNodeType.OBJECT);
ObjectReader mockedMapper = mock(ObjectReader.class);
JsonNodeClaim claim = (JsonNodeClaim) JsonNodeClaim.claimFromNode(value, mockedMapper);
JsonNodeClaim spiedClaim = spy(claim);
JsonParser mockedParser = mock(JsonParser.class);
when(mockedMapper.treeAsTokens(value)).thenReturn(mockedParser);
when(mockedParser.readValueAs(ArgumentMatchers.any(TypeReference.class))).thenThrow(IOException.class);
exception.expect(JWTDecodeException.class);
spiedClaim.asMap();
}
代码示例来源: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: line/armeria
@Override
public int readI32() throws TException {
final Class<?> fieldClass = getCurrentFieldClassIfIs(TEnum.class);
if (fieldClass != null) {
// Enum fields may be set by string, even though they represent integers.
getCurrentContext().read();
final JsonNode elem = getCurrentContext().getCurrentChild();
if (elem.isInt()) {
return TypedParser.INTEGER.readFromJsonElement(elem);
} else if (elem.isTextual()) {
// All TEnum are enums
@SuppressWarnings({ "unchecked", "rawtypes" })
final TEnum tEnum = (TEnum) Enum.valueOf((Class<Enum>) fieldClass,
TypedParser.STRING.readFromJsonElement(elem));
return tEnum.getValue();
} else {
throw new TTransportException("invalid value type for enum field: " + elem.getNodeType() +
" (" + elem + ')');
}
} else {
return readNameOrValue(TypedParser.INTEGER);
}
}
内容来源于网络,如有侵权,请联系作者删除!