@Test(expected = IllegalArgumentException.class) public void convertStringArrayToBinary() { String[] bytes = { "0x01", "0x02" }; SchemaValueConverter.convert(Schema.Type.BINARY, bytes); }
public static Object convert(Schema.Type type, Object value) { if (value == null) { return null; } switch (type) { case BOOLEAN: if (value instanceof Boolean) { return value; } else if (value instanceof String) { return Boolean.valueOf((String) value); } break; case BYTE: case SHORT: case INTEGER: case LONG: case FLOAT: case DOUBLE: return convertNumber(type, value); case STRING: if (value instanceof String) { return value; } break; case BINARY: if (value instanceof byte[]) { return value; } break; case NESTED: if (value instanceof Map) { return value; } break; case ARRAY: if (value instanceof List) { return value; } break; } throw new IllegalArgumentException("Cannot convert value " + value + " with Java type class " + value.getClass() + " to type " + type); }
SchemaValueConverter { public static Object convert(Schema.Type type, Object value) { if (value == null) { return null; } switch (type) { case BOOLEAN: if (value instanceof Boolean) { return value; } else if (value instanceof String) { return Boolean.valueOf((String) value); } break; case BYTE: case SHORT: case INTEGER: case LONG: case FLOAT: case DOUBLE: return convertNumber(type, value); case STRING: if (value instanceof String) { return value; } break; case BINARY: if (value instanceof byte[]) { return value; } break; case NESTED: if (value instanceof Map) { return value; } break; case ARRAY: if (value instanceof List) { return value; } break; } throw new IllegalArgumentException("Cannot convert value " + value + " with Java type class " + value.getClass() + " to type " + type); } }
SchemaValueConverter { public static Object convert(Schema.Type type, Object value) { if (value == null) { return null; } switch (type) { case BOOLEAN: if (value instanceof Boolean) { return value; } else if (value instanceof String) { return Boolean.valueOf((String) value); } break; case BYTE: case SHORT: case INTEGER: case LONG: case FLOAT: case DOUBLE: return convertNumber(type, value); case STRING: if (value instanceof String) { return value; } break; case BINARY: if (value instanceof byte[]) { return value; } break; case NESTED: if (value instanceof Map) { return value; } break; case ARRAY: if (value instanceof List) { return value; } break; } throw new IllegalArgumentException("Cannot convert value " + value + " with Java type class " + value.getClass() + " to type " + type); } private  SchemaValueConverter(); }
SchemaValueConverter { public static Object convert(Schema.Type type, Object value) { if (value == null) { return null; } switch (type) { case BOOLEAN: if (value instanceof Boolean) { return value; } else if (value instanceof String) { return Boolean.valueOf((String) value); } break; case BYTE: case SHORT: case INTEGER: case LONG: case FLOAT: case DOUBLE: return convertNumber(type, value); case STRING: if (value instanceof String) { return value; } break; case BINARY: if (value instanceof byte[]) { return value; } break; case NESTED: if (value instanceof Map) { return value; } break; case ARRAY: if (value instanceof List) { return value; } break; } throw new IllegalArgumentException("Cannot convert value " + value + " with Java type class " + value.getClass() + " to type " + type); } private  SchemaValueConverter(); static Map<String, Object> convertMap(Schema schema, Map<String, Object> value); static Object convert(Schema.Type type, Object value); }
SchemaValueConverter { public static Object convert(Schema.Type type, Object value) { if (value == null) { return null; } switch (type) { case BOOLEAN: if (value instanceof Boolean) { return value; } else if (value instanceof String) { return Boolean.valueOf((String) value); } break; case BYTE: case SHORT: case INTEGER: case LONG: case FLOAT: case DOUBLE: return convertNumber(type, value); case STRING: if (value instanceof String) { return value; } break; case BINARY: if (value instanceof byte[]) { return value; } break; case NESTED: if (value instanceof Map) { return value; } break; case ARRAY: if (value instanceof List) { return value; } break; } throw new IllegalArgumentException("Cannot convert value " + value + " with Java type class " + value.getClass() + " to type " + type); } private  SchemaValueConverter(); static Map<String, Object> convertMap(Schema schema, Map<String, Object> value); static Object convert(Schema.Type type, Object value);  }