Java Code Examples for org.codehaus.jackson.JsonNode#getBooleanValue()

The following examples show how to use org.codehaus.jackson.JsonNode#getBooleanValue() . 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: GenericEntityDeserializer.java    From secure-data-service with Apache License 2.0 6 votes vote down vote up
private Object processPrimitive(final JsonNode prim) {
    Object val;
    
    if (prim instanceof BooleanNode) {
        val = prim.getBooleanValue();
    } else if (prim instanceof DoubleNode) {
        val = prim.getDoubleValue();
    } else if (prim instanceof IntNode) {
        val = prim.getIntValue();
    } else if (prim instanceof LongNode) {
        val = prim.getLongValue();
    } else {
        val = prim.getTextValue();
    }
    return val;
}
 
Example 2
Source File: BasicRESTClient.java    From secure-data-service with Apache License 2.0 6 votes vote down vote up
@Override
public String sessionCheck(final String token) throws URISyntaxException, IOException {
    LOGGER.info("Session check URL = " + SESSION_CHECK_PREFIX);
    URL url = new URL(apiServerUri + "/" + SESSION_CHECK_PREFIX);
    Response response = getRequest(url);
    String jsonText = response.readEntity(String.class);
    ObjectMapper mapper = new ObjectMapper();
    JsonNode obj = mapper.readTree(jsonText);
    if (obj.has("authenticated")) {
        JsonNode e = obj.get("authenticated");
        if (e.getBooleanValue()) {
            return sessionToken;
        }
    }
    return "";
}
 
Example 3
Source File: JsonUtils.java    From Cubert with Apache License 2.0 5 votes vote down vote up
public static Object asObject(JsonNode node)
{
    if (node.isTextual())
        return node.getTextValue();
    else if (node.isInt())
        return node.getIntValue();
    else if (node.isFloatingPointNumber())
        return node.getDoubleValue();
    else if (node.isBoolean())
        return node.getBooleanValue();

    return null;
}
 
Example 4
Source File: AbstractSiteToSiteReportingTask.java    From nifi with Apache License 2.0 4 votes vote down vote up
protected Object getRawNodeValue(final JsonNode fieldNode, final DataType dataType) throws IOException {
    if (fieldNode == null || fieldNode.isNull()) {
        return null;
    }

    if (fieldNode.isNumber()) {
        return fieldNode.getNumberValue();
    }

    if (fieldNode.isBinary()) {
        return fieldNode.getBinaryValue();
    }

    if (fieldNode.isBoolean()) {
        return fieldNode.getBooleanValue();
    }

    if (fieldNode.isTextual()) {
        return fieldNode.getTextValue();
    }

    if (fieldNode.isArray()) {
        final ArrayNode arrayNode = (ArrayNode) fieldNode;
        final int numElements = arrayNode.size();
        final Object[] arrayElements = new Object[numElements];
        int count = 0;

        final DataType elementDataType;
        if (dataType != null && dataType.getFieldType() == RecordFieldType.ARRAY) {
            final ArrayDataType arrayDataType = (ArrayDataType) dataType;
            elementDataType = arrayDataType.getElementType();
        } else {
            elementDataType = null;
        }

        for (final JsonNode node : arrayNode) {
            final Object value = getRawNodeValue(node, elementDataType);
            arrayElements[count++] = value;
        }

        return arrayElements;
    }

    if (fieldNode.isObject()) {
        RecordSchema childSchema;
        if (dataType != null && RecordFieldType.RECORD == dataType.getFieldType()) {
            final RecordDataType recordDataType = (RecordDataType) dataType;
            childSchema = recordDataType.getChildSchema();
        } else {
            childSchema = null;
        }

        if (childSchema == null) {
            childSchema = new SimpleRecordSchema(Collections.emptyList());
        }

        final Iterator<String> fieldNames = fieldNode.getFieldNames();
        final Map<String, Object> childValues = new HashMap<>();
        while (fieldNames.hasNext()) {
            final String childFieldName = fieldNames.next();
            final Object childValue = getRawNodeValue(fieldNode.get(childFieldName), dataType);
            childValues.put(childFieldName, childValue);
        }

        final MapRecord record = new MapRecord(childSchema, childValues);
        return record;
    }

    return null;
}