Java Code Examples for com.fasterxml.jackson.databind.JsonNode#isBinary()

The following examples show how to use com.fasterxml.jackson.databind.JsonNode#isBinary() . 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: RangeBoundValueDeserializer.java    From presto with Apache License 2.0 6 votes vote down vote up
private Object toValue(JsonNode node)
        throws IOException
{
    if (node.isTextual()) {
        return node.asText();
    }
    else if (node.isNumber()) {
        return node.numberValue();
    }
    else if (node.isBoolean()) {
        return node.asBoolean();
    }
    else if (node.isBinary()) {
        return node.binaryValue();
    }
    else {
        throw new IllegalStateException("Unexpected range bound value: " + node);
    }
}
 
Example 2
Source File: TreeTraversingParser.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public String getText()
{
    if (_closed) {
        return null;
    }
    // need to separate handling a bit...
    switch (_currToken) {
    case FIELD_NAME:
        return _nodeCursor.getCurrentName();
    case VALUE_STRING:
        return currentNode().textValue();
    case VALUE_NUMBER_INT:
    case VALUE_NUMBER_FLOAT:
        return String.valueOf(currentNode().numberValue());
    case VALUE_EMBEDDED_OBJECT:
        JsonNode n = currentNode();
        if (n != null && n.isBinary()) {
            // this will convert it to base64
            return n.asText();
        }
    default:
    	return (_currToken == null) ? null : _currToken.asString();
    }
}
 
Example 3
Source File: TreeTraversingParser.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Object getEmbeddedObject()
{
    if (!_closed) {
        JsonNode n = currentNode();
        if (n != null) {
            if (n.isPojo()) {
                return ((POJONode) n).getPojo();
            }
            if (n.isBinary()) {
                return ((BinaryNode) n).binaryValue();
            }
        }
    }
    return null;
}
 
Example 4
Source File: RangeBoundValueDeserializer.java    From presto-kudu with Apache License 2.0 5 votes vote down vote up
private Object toValue(JsonNode node) throws IOException {
    if (node.isTextual()) {
        return node.asText();
    } else if (node.isNumber()) {
        return node.numberValue();
    } else if (node.isBoolean()) {
        return node.asBoolean();
    } else if (node.isBinary()) {
        return node.binaryValue();
    } else {
        throw new IllegalStateException("Unexpected range bound value: " + node);
    }
}
 
Example 5
Source File: RosettaBinder.java    From Rosetta with Apache License 2.0 5 votes vote down vote up
private Object unwrapJsonValue(JsonNode node) {
  if (node.isNull()) {
    return null;
  } else if (node.isBoolean()) {
    return node.booleanValue();
  } else if (node.isBinary()) {
    return ((BinaryNode) node).binaryValue();
  } else if (node.isNumber()) {
    return node.numberValue();
  } else {
    return node.asText();
  }
}
 
Example 6
Source File: CassandraPersistenceUtils.java    From usergrid with Apache License 2.0 5 votes vote down vote up
public static Object toStorableValue( Object obj ) {
    if ( obj == null ) {
        return null;
    }

    if ( isBasicType( obj.getClass() ) ) {
        return obj;
    }

    if ( obj instanceof ByteBuffer ) {
        return obj;
    }

    JsonNode json = toJsonNode( obj );
    if ( ( json != null ) && json.isValueNode() ) {
        if ( json.isBigInteger() ) {
            return json.asInt();
        }
        else if ( json.isNumber() || json.isBoolean() ) {
            return BigInteger.valueOf( json.asLong() );
        }
        else if ( json.isTextual() ) {
            return json.asText();
        }
        else if ( json.isBinary() ) {
            try {
                return wrap( json.binaryValue() );
            }
            catch ( IOException e ) {
            }
        }
    }

    return json;
}
 
Example 7
Source File: AvroJson.java    From parquet-mr with Apache License 2.0 4 votes vote down vote up
private static boolean matches(JsonNode datum, Schema schema) {
  switch (schema.getType()) {
    case RECORD:
      if (datum.isObject()) {
        // check that each field is present or has a default
        boolean missingField = false;
        for (Schema.Field field : schema.getFields()) {
          if (!datum.has(field.name()) && field.defaultVal() == null) {
            missingField = true;
            break;
          }
        }
        if (!missingField) {
          return true;
        }
      }
      break;
    case UNION:
      if (resolveUnion(datum, schema.getTypes()) != null) {
        return true;
      }
      break;
    case MAP:
      if (datum.isObject()) {
        return true;
      }
      break;
    case ARRAY:
      if (datum.isArray()) {
        return true;
      }
      break;
    case BOOLEAN:
      if (datum.isBoolean()) {
        return true;
      }
      break;
    case FLOAT:
      if (datum.isFloat() || datum.isInt()) {
        return true;
      }
      break;
    case DOUBLE:
      if (datum.isDouble() || datum.isFloat() ||
          datum.isLong() || datum.isInt()) {
        return true;
      }
      break;
    case INT:
      if (datum.isInt()) {
        return true;
      }
      break;
    case LONG:
      if (datum.isLong() || datum.isInt()) {
        return true;
      }
      break;
    case STRING:
      if (datum.isTextual()) {
        return true;
      }
      break;
    case ENUM:
      if (datum.isTextual() && schema.hasEnumSymbol(datum.textValue())) {
        return true;
      }
      break;
    case BYTES:
    case FIXED:
      if (datum.isBinary()) {
        return true;
      }
      break;
    case NULL:
      if (datum == null || datum.isNull()) {
        return true;
      }
      break;
    default: // UNION or unknown
      throw new IllegalArgumentException("Unsupported schema: " + schema);
  }
  return false;
}
 
Example 8
Source File: QueueIndexUpdate.java    From usergrid with Apache License 2.0 4 votes vote down vote up
/**
 * @param obj
 * @return
 */
public static Object toIndexableValue( Object obj ) {
    if ( obj == null ) {
        return null;
    }

    if ( obj instanceof String ) {
        return prepStringForIndex( ( String ) obj );
    }

    // UUIDs, and BigIntegers map to Cassandra UTF8Type and IntegerType
    if ( ( obj instanceof UUID ) || ( obj instanceof BigInteger ) ) {
        return obj;
    }

    // For any numeric values, turn them into a long
    // and make them BigIntegers for IntegerType
    if ( obj instanceof Number ) {
        return BigInteger.valueOf( ( ( Number ) obj ).longValue() );
    }

    if ( obj instanceof Boolean ) {
        return BigInteger.valueOf( ( ( Boolean ) obj ) ? 1L : 0L );
    }

    if ( obj instanceof Date ) {
        return BigInteger.valueOf( ( ( Date ) obj ).getTime() );
    }

    if ( obj instanceof byte[] ) {
        return wrap( ( byte[] ) obj );
    }

    if ( obj instanceof ByteBuffer ) {
        return obj;
    }

    JsonNode json = toJsonNode( obj );
    if ( ( json != null ) && json.isValueNode() ) {
        if ( json.isBigInteger() ) {
            return json.asInt();
            //return json.getBigIntegerValue();
        }
        else if ( json.isNumber() || json.isBoolean() ) {
            return BigInteger.valueOf( json.asLong() );
        }
        else if ( json.isTextual() ) {
            return prepStringForIndex( json.asText() );
        }
        else if ( json.isBinary() ) {
            try {
                return wrap( json.binaryValue());
            }
            catch ( IOException e ) {
            }
        }
    }

    return null;
}
 
Example 9
Source File: JsonUtil.java    From kite with Apache License 2.0 4 votes vote down vote up
private static boolean matches(JsonNode datum, Schema schema) {
  switch (schema.getType()) {
    case RECORD:
      if (datum.isObject()) {
        // check that each field is present or has a default
        boolean missingField = false;
        for (Schema.Field field : schema.getFields()) {
          if (!datum.has(field.name()) && field.defaultValue() == null) {
            missingField = true;
            break;
          }
        }
        if (!missingField) {
          return true;
        }
      }
      break;
    case UNION:
      if (resolveUnion(datum, schema.getTypes()) != null) {
        return true;
      }
      break;
    case MAP:
      if (datum.isObject()) {
        return true;
      }
      break;
    case ARRAY:
      if (datum.isArray()) {
        return true;
      }
      break;
    case BOOLEAN:
      if (datum.isBoolean()) {
        return true;
      }
      break;
    case FLOAT:
      if (datum.isFloat() || datum.isInt()) {
        return true;
      }
      break;
    case DOUBLE:
      if (datum.isDouble() || datum.isFloat() ||
          datum.isLong() || datum.isInt()) {
        return true;
      }
      break;
    case INT:
      if (datum.isInt()) {
        return true;
      }
      break;
    case LONG:
      if (datum.isLong() || datum.isInt()) {
        return true;
      }
      break;
    case STRING:
      if (datum.isTextual()) {
        return true;
      }
      break;
    case ENUM:
      if (datum.isTextual() && schema.hasEnumSymbol(datum.textValue())) {
        return true;
      }
      break;
    case BYTES:
    case FIXED:
      if (datum.isBinary()) {
        return true;
      }
      break;
    case NULL:
      if (datum == null || datum.isNull()) {
        return true;
      }
      break;
    default: // UNION or unknown
      throw new IllegalArgumentException("Unsupported schema: " + schema);
  }
  return false;
}