Search in sources :

Example 1 with JsonNode

use of com.couchbase.client.deps.com.fasterxml.jackson.databind.JsonNode in project YCSB by brianfrankcooper.

the class BackoffSelectStrategy method decode.

/**
   * Decode the String from server and pass it into the decoded destination.
   *
   * @param source the loaded object.
   * @param fields the fields to check.
   * @param dest the result passed back to YCSB.
   */
private void decode(final String source, final Set<String> fields, final HashMap<String, ByteIterator> dest) {
    try {
        JsonNode json = JacksonTransformers.MAPPER.readTree(source);
        boolean checkFields = fields != null && !fields.isEmpty();
        for (Iterator<Map.Entry<String, JsonNode>> jsonFields = json.fields(); jsonFields.hasNext(); ) {
            Map.Entry<String, JsonNode> jsonField = jsonFields.next();
            String name = jsonField.getKey();
            if (checkFields && !fields.contains(name)) {
                continue;
            }
            JsonNode jsonValue = jsonField.getValue();
            if (jsonValue != null && !jsonValue.isNull()) {
                dest.put(name, new StringByteIterator(jsonValue.asText()));
            }
        }
    } catch (Exception e) {
        throw new RuntimeException("Could not decode JSON");
    }
}
Also used : StringByteIterator(com.yahoo.ycsb.StringByteIterator) JsonNode(com.couchbase.client.deps.com.fasterxml.jackson.databind.JsonNode) TemporaryFailureException(com.couchbase.client.java.error.TemporaryFailureException) DBException(com.yahoo.ycsb.DBException)

Example 2 with JsonNode

use of com.couchbase.client.deps.com.fasterxml.jackson.databind.JsonNode in project YCSB by brianfrankcooper.

the class BackoffSelectStrategy method decode.

/**
 * Decode the String from server and pass it into the decoded destination.
 *
 * @param source the loaded object.
 * @param fields the fields to check.
 * @param dest the result passed back to YCSB.
 */
private void decode(final String source, final Set<String> fields, final Map<String, ByteIterator> dest) {
    try {
        JsonNode json = JacksonTransformers.MAPPER.readTree(source);
        boolean checkFields = fields != null && !fields.isEmpty();
        for (Iterator<Map.Entry<String, JsonNode>> jsonFields = json.fields(); jsonFields.hasNext(); ) {
            Map.Entry<String, JsonNode> jsonField = jsonFields.next();
            String name = jsonField.getKey();
            if (checkFields && !fields.contains(name)) {
                continue;
            }
            JsonNode jsonValue = jsonField.getValue();
            if (jsonValue != null && !jsonValue.isNull()) {
                dest.put(name, new StringByteIterator(jsonValue.asText()));
            }
        }
    } catch (Exception e) {
        throw new RuntimeException("Could not decode JSON");
    }
}
Also used : StringByteIterator(site.ycsb.StringByteIterator) JsonNode(com.couchbase.client.deps.com.fasterxml.jackson.databind.JsonNode) TemporaryFailureException(com.couchbase.client.java.error.TemporaryFailureException) DBException(site.ycsb.DBException)

Aggregations

JsonNode (com.couchbase.client.deps.com.fasterxml.jackson.databind.JsonNode)2 TemporaryFailureException (com.couchbase.client.java.error.TemporaryFailureException)2 DBException (com.yahoo.ycsb.DBException)1 StringByteIterator (com.yahoo.ycsb.StringByteIterator)1 DBException (site.ycsb.DBException)1 StringByteIterator (site.ycsb.StringByteIterator)1