Java Code Examples for com.fasterxml.jackson.databind.node.JsonNodeType#BOOLEAN

The following examples show how to use com.fasterxml.jackson.databind.node.JsonNodeType#BOOLEAN . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JsonCacheImpl.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
protected JsonNodeType nodeTypeFor(Object value) {
    JsonNodeType type;
    if (value == null) {
        type = JsonNodeType.NULL;
    } else if (value instanceof Boolean) {
        type = JsonNodeType.BOOLEAN;
    } else if (value instanceof Number) {
        type = JsonNodeType.NUMBER;
    } else if (value instanceof String) {
        type = JsonNodeType.STRING;
    } else if (value instanceof ArrayNode || value instanceof List) {
        type = JsonNodeType.ARRAY;
    } else if (value instanceof byte[]) {
        type = JsonNodeType.BINARY;
    } else if (value instanceof ObjectNode || value instanceof Map) {
        type = JsonNodeType.OBJECT;
    } else {
        type = JsonNodeType.POJO;
    }
    return type;
}
 
Example 2
Source File: DefaultHealthCheckUpdateHandler.java    From armeria with Apache License 2.0 6 votes vote down vote up
private static HealthCheckUpdateResult handlePut(AggregatedHttpRequest req) {
    final JsonNode json = toJsonNode(req);
    if (json.getNodeType() != JsonNodeType.OBJECT) {
        throw HttpStatusException.of(HttpStatus.BAD_REQUEST);
    }

    final JsonNode healthy = json.get("healthy");
    if (healthy == null) {
        throw HttpStatusException.of(HttpStatus.BAD_REQUEST);
    }
    if (healthy.getNodeType() != JsonNodeType.BOOLEAN) {
        throw HttpStatusException.of(HttpStatus.BAD_REQUEST);
    }

    return healthy.booleanValue() ? HealthCheckUpdateResult.HEALTHY
                                  : HealthCheckUpdateResult.UNHEALTHY;
}
 
Example 3
Source File: CustomAttributeDeserializer.java    From intercom-java with Apache License 2.0 5 votes vote down vote up
@Override
public CustomAttribute deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
    CustomAttribute cda = null;
    final String currentName = jp.getParsingContext().getCurrentName();
    final ObjectMapper mapper = (ObjectMapper) jp.getCodec();
    final ValueNode vNode = mapper.readTree(jp);
    if (vNode.asToken().isScalarValue()) {
        if (vNode.getNodeType() == JsonNodeType.BOOLEAN) {
            cda = new CustomAttribute<Boolean>(currentName, vNode.asBoolean(), Boolean.class);
        } else if (vNode.getNodeType() == JsonNodeType.STRING) {
            cda = new CustomAttribute<String>(currentName, vNode.asText(), String.class);
        } else if (vNode.getNodeType() == JsonNodeType.NUMBER) {
            final NumericNode nNode = (NumericNode) vNode;
            if (currentName.endsWith("_at")) {
                cda = new CustomAttribute<Long>(currentName, vNode.longValue(), Long.class);
            } else if (nNode.isInt()) {
                cda = new CustomAttribute<Integer>(currentName, vNode.intValue(), Integer.class);
            } else if (nNode.isFloat()) {
                cda = new CustomAttribute<Float>(currentName, vNode.floatValue(), Float.class);
            } else if (nNode.isDouble()) {
                cda = new CustomAttribute<Double>(currentName, vNode.doubleValue(), Double.class);
            } else if (nNode.isLong()) {
                cda = new CustomAttribute<Long>(currentName, vNode.longValue(), Long.class);
            } else {
                cda = new CustomAttribute<String>(currentName, vNode.asText(), String.class);
            }
        } else {
            cda = new CustomAttribute<String>(currentName, vNode.asText(), String.class);
        }
    }
    return cda;
}
 
Example 4
Source File: JsonQueryObjectModelConverter.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
private void parseProperties(QueryPart queryPart, ObjectNode properties) throws QueryException {
	Iterator<Entry<String, JsonNode>> fields = properties.fields();
	while (fields.hasNext()) {
		Entry<String, JsonNode> entry = fields.next();
		String propertySetName = entry.getKey();
		JsonNode value = entry.getValue();
		if (value.isObject()) {
			ObjectNode set = (ObjectNode)value;
			Iterator<Entry<String, JsonNode>> propertySetFields = set.fields();
			while (propertySetFields.hasNext()) {
				Entry<String, JsonNode> propertyEntry = propertySetFields.next();
				JsonNode propertyValue = propertyEntry.getValue();
				
				if (propertyValue.isValueNode()) {
					if (propertyValue.getNodeType() == JsonNodeType.BOOLEAN) {
						queryPart.addProperty(propertySetName, propertyEntry.getKey(), propertyValue.asBoolean());
					} else if (propertyValue.getNodeType() == JsonNodeType.NUMBER) {
						queryPart.addProperty(propertySetName, propertyEntry.getKey(), propertyValue.asDouble());
					} else if (propertyValue.getNodeType() == JsonNodeType.STRING) {
						queryPart.addProperty(propertySetName, propertyEntry.getKey(), propertyValue.asText());
					} else if (propertyValue.getNodeType() == JsonNodeType.NULL) {
						queryPart.addProperty(propertySetName, propertyEntry.getKey(), null);
					}
				} else {
					throw new QueryException("property \"" + propertyEntry.getKey() + "\" type not supported");
				}
			}				
		} else {
			throw new QueryException("Query language has changed, propertyset name required now");
		}
	}
}
 
Example 5
Source File: IsJsonBoolean.java    From java-hamcrest with Apache License 2.0 4 votes vote down vote up
private IsJsonBoolean(Matcher<? super Boolean> booleanMatcher) {
  super(JsonNodeType.BOOLEAN);
  this.booleanMatcher = Objects.requireNonNull(booleanMatcher);
}
 
Example 6
Source File: JsonNode.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * 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;
}