Example usage for com.fasterxml.jackson.databind JsonNode textValue

List of usage examples for com.fasterxml.jackson.databind JsonNode textValue

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind JsonNode textValue.

Prototype

public String textValue() 

Source Link

Usage

From source file:com.redhat.lightblue.crud.rdbms.RDBMSProcessor.java

public static void process(RDBMSContext rdbmsContext) {
    RDBMS rdbms = (RDBMS) rdbmsContext.getEntityMetadata().getEntitySchema().getProperties().get("rdbms");
    if (rdbms == null) {
        throw new IllegalStateException(
                "Configured to use RDBMS but no RDBMS definition was found for the entity");
    }// w ww. j av  a 2s .  c  o m
    rdbmsContext.setRdbms(rdbms);
    RDBMSDataStore d = (RDBMSDataStore) rdbmsContext.getEntityMetadata().getDataStore();
    DataSource ds = rdbmsContext.getRDBMSDataSourceResolver().get(d);
    rdbmsContext.setDataSource(ds);
    rdbmsContext.setRowMapper(new VariableUpdateRowMapper(rdbmsContext));

    String crudOperationName = rdbmsContext.getCRUDOperationName();
    if (crudOperationName.equals("find")) {
        crudOperationName = LightblueOperators.FETCH;
    }
    Operation op = rdbmsContext.getRdbms().getOperationByName(crudOperationName);
    if (op == null) {
        op = new Operation();
        op.setName(crudOperationName);
        op.setBindings(new Bindings());
        op.getBindings().setInList(new ArrayList<InOut>());
        op.getBindings().setOutList(new ArrayList<InOut>());
        rdbmsContext.getRdbms().setOperationByName(crudOperationName, op);
        op.getBindings().setInList(rdbmsContext.getIn());
        op.getBindings().setOutList(rdbmsContext.getOut());
    }
    if (op.getBindings().getInList() != null) {
        rdbmsContext.setIn(op.getBindings().getInList());
    }
    if (op.getBindings().getOutList() != null) {
        rdbmsContext.setOut(op.getBindings().getOutList());
    }

    if (rdbmsContext.getQueryExpression() != null) {
        // Dynamically create the first SQL statements to generate the input for the next defined expressions
        List<SelectStmt> inputStmt = Translator.getImpl(rdbmsContext.getRdbms().getDialect())
                .translate(rdbmsContext);

        rdbmsContext.setInitialInput(true);
        new ExecuteSQLCommand(rdbmsContext, inputStmt).execute();
        rdbmsContext.setInitialInput(false);

        mapInputWithBinding(rdbmsContext);
    } else {
        // if no query was informed, the RDBMS module will try to convert the data from the request
        List<DocCtx> documents = rdbmsContext.getCrudOperationContext().getDocuments();
        for (DocCtx docCtx : documents) {
            List<ColumnToField> columnToFieldMap = rdbmsContext.getRdbms().getSQLMapping()
                    .getColumnToFieldMap();
            for (ColumnToField ctf : columnToFieldMap) {
                Path path = new Path(ctf.getField());
                JsonNode jsonNode = docCtx.get(path);
                rdbmsContext.getInVar().put(jsonNode.textValue(), String.class,
                        Column.createTemp(ctf.getField(), String.class.getCanonicalName()));
            }
        }
    }
    if (rdbmsContext.getUpdateExpression() != null) {
        recursiveMapInputUpdateExpression(rdbmsContext, rdbmsContext.getUpdateExpression());
    }

    // Process the defined expressions
    recursiveExpressionCall(rdbmsContext, op, op.getExpressionList());

    // processed final output
    if (op.getExpressionList() == null || op.getExpressionList().isEmpty()) {
        convertInputToProjection(rdbmsContext);
    } else {
        convertOutputToProjection(rdbmsContext);
    }
}

From source file:com.gsma.mobileconnect.utils.AndroidJsonUtils.java

/**
 * Return the string value of an optional child node.
 * <p>/*from  w  w  w . j av  a2 s . c  om*/
 * Check the parent node for the named child, if found return the string contents of the child node, return null otherwise.
 *
 * @param parentNode The node to check.
 * @param name Name of the optional child node.
 * @return Text value of child node, if found, null otherwise.
 */
public static String getOptionalStringValue(JsonNode parentNode, String name) {
    JsonNode childNode = parentNode.get(name);
    if (null == childNode) {
        return null;
    } else {
        return childNode.textValue();
    }
}

From source file:com.gsma.mobileconnect.utils.AndroidJsonUtils.java

/**
 * Query the parent node for the named child node and return the text value of the child node
 *
 * @param parentNode Node to check./*from w ww  .j  a  va2  s  .c o m*/
 * @param name Name of the child node.
 * @return The text value of the child node.
 * @throws NoFieldException Thrown if field not found.
 */
public static String getExpectedStringValue(JsonNode parentNode, String name) throws NoFieldException {
    JsonNode childNode = parentNode.get(name);
    if (null == childNode) {
        throw new NoFieldException(name);
    }
    return childNode.textValue();
}

From source file:org.kiji.rest.representations.KijiRestEntityId.java

/**
 * Create a list of KijiRestEntityIds from a string input, which can be a json array of valid
 * entity id strings and/or valid hbase row keys.
 * This method is used for entity ids specified from the URL.
 *
 * @param entityIdListString string of a json array of rows identifiers.
 * @param layout of the table in which the entity id belongs.
 *        If null, then long components may not be recognized.
 * @return a properly constructed list of KijiRestEntityIds.
 * @throws IOException if KijiRestEntityId list can not be properly constructed.
 *//*from   ww  w  .  ja  v  a  2 s. c om*/
public static List<KijiRestEntityId> createListFromUrl(final String entityIdListString,
        final KijiTableLayout layout) throws IOException {
    final JsonParser parser = new JsonFactory().createJsonParser(entityIdListString)
            .enable(Feature.ALLOW_COMMENTS).enable(Feature.ALLOW_SINGLE_QUOTES)
            .enable(Feature.ALLOW_UNQUOTED_FIELD_NAMES);
    final JsonNode jsonNode = BASIC_MAPPER.readTree(parser);

    List<KijiRestEntityId> kijiRestEntityIds = Lists.newArrayList();

    if (jsonNode.isArray()) {
        for (JsonNode node : jsonNode) {
            if (node.isTextual()) {
                kijiRestEntityIds.add(createFromUrl(node.textValue(), layout));
            } else {
                kijiRestEntityIds.add(createFromUrl(node.toString(), layout));
            }
        }
    } else {
        throw new IOException("The entity id list string is not a valid json array.");
    }

    return kijiRestEntityIds;
}

From source file:com.collective.celos.Util.java

public static String getStringProperty(ObjectNode properties, String name) {
    JsonNode node = properties.get(name);
    if (node == null) {
        throw new IllegalArgumentException("Property " + name + " not set.");
    } else if (!node.isTextual()) {
        throw new IllegalArgumentException("Property " + name + " is not a string, but " + node);
    } else {//from w  w w .j  a  v a  2  s.co m
        return node.textValue();
    }
}

From source file:org.pac4j.oauth.profile.JsonHelper.java

/**
 * Return the field with name in JSON (a string, a boolean, a number or a node).
 *
 * @param json json//  ww  w .  j  av a2 s  .c  o m
 * @param name node name
 * @return the field
 */
public static Object get(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 {
                return node;
            }
        }
    }
    return null;
}

From source file:com.palominolabs.crm.sf.rest.RestConnectionImpl.java

@Nonnull
private static String getString(ObjectNode jsonNode, String key) throws ResponseParseException {
    JsonNode node = getNode(jsonNode, key);
    if (!node.isTextual()) {
        throw new ResponseParseException("Node <" + node + "> isn't text for key <" + key + ">");
    }//from  w  w w .  j  av  a 2  s  .  c om
    return node.textValue();
}

From source file:org.level28.android.moca.json.TwitterSearchDeserializer.java

/**
 * Parse a single tweet.//ww w  .j ava  2s.com
 */
private static Tweet parseSingleTweet(JsonNode objectRoot) throws JsonDeserializerException {
    // Basic sanity check
    if (!objectRoot.isObject()) {
        throw new JsonDeserializerException("Tweet JsonNode is not an object");
    }
    JsonNode node;
    Tweet tweet = new Tweet();

    // When was this tweet created?
    node = objectRoot.path("created_at");
    if (node.isMissingNode() || !node.isTextual()) {
        throw new JsonDeserializerException("'created_at' missing or invalid");
    }
    try {
        tweet.setCreatedAt(mDateFormat.parse(node.textValue()));
    } catch (ParseException e) {
        throw new JsonDeserializerException("Invalid date specified in 'created_at'", e);
    }

    // Who sent it? (user handle)
    node = objectRoot.path("from_user");
    if (node.isMissingNode() || !node.isTextual()) {
        throw new JsonDeserializerException("'from_user' missing or invalid");
    }
    tweet.setFromUser(node.textValue());

    // Who sent it? (user id)
    node = objectRoot.path("from_user_id");
    if (node.isMissingNode() || !node.canConvertToLong()) {
        throw new JsonDeserializerException("'from_user_id' missing or invalid");
    }
    tweet.setFromUserId(node.asLong());

    // Tweet id
    node = objectRoot.path("id");
    if (node.isMissingNode() || !node.canConvertToLong()) {
        throw new JsonDeserializerException("'id' missing or invalid");
    }
    tweet.setId(node.asLong());

    // Profile image url - prefer https over http
    node = objectRoot.path("profile_image_url_https");
    if (node.isMissingNode() || !node.isTextual()) {
        // Fall back to http
        node = objectRoot.path("profile_image_url");
        if (node.isMissingNode() || !node.isTextual()) {
            throw new JsonDeserializerException("'profile_image_url' missing or invalid");
        }
    }
    tweet.setProfileImageUrl(node.textValue());

    // Finally: tweet contents!
    node = objectRoot.path("text");
    if (node.isMissingNode() || !node.isTextual()) {
        throw new JsonDeserializerException("'text' missing or invalid");
    }
    tweet.setText(node.textValue());

    // FIXME: entities

    // Optional fields
    // Who sent it? (display name - yes, apparently this is OPTIONAL!)
    tweet.setFromUserName(objectRoot.path("from_user_name").textValue());

    // Free-form location
    tweet.setLocation(objectRoot.path("location").textValue());

    // FIXME: geo

    // End of tweet :-)
    return tweet;
}

From source file:com.attribyte.essem.util.Util.java

/**
 * Gets the first value of an array as a string, the value if node is not array or null.
 * @param fieldsObj The object containing fields.
 * @param key The key.//  w w w . j av  a 2s.com
 * @return The value or <code>null</code>.
 */
public static String getStringField(final JsonNode fieldsObj, final String key) {
    JsonNode fieldNode = getFieldNode(fieldsObj, key);
    return fieldNode != null ? fieldNode.textValue() : null;
}

From source file:com.pros.jsontransform.expression.FunctionAbstract.java

static JsonNode transformArgument(final JsonNode argumentNode, final ObjectTransformer transformer)
        throws ObjectTransformerException {
    ObjectNode resultNode = transformer.mapper.createObjectNode();

    if (argumentNode.isContainerNode()) {
        // transform argument node
        JsonNode sourceNode = transformer.getSourceNode();
        JsonNode valueNode = transformer.transformExpression(sourceNode, argumentNode);
        resultNode.put("result", valueNode);
    } else if (argumentNode.isTextual()) {
        // transform $i modifier
        String textValue = argumentNode.textValue();
        if (textValue.contains($I)) {
            int arrayIndex = transformer.getIndexOfSourceArray();
            textValue = textValue.replace($I, String.valueOf(arrayIndex));
        }//from  ww w. j  a  va  2s .com
        resultNode.put("result", textValue);
    } else {
        resultNode.put("result", argumentNode);
    }

    return resultNode.get("result");
}