private static BigDecimal convertToDecimal(Schema toSchema, Object value) {
        if (value instanceof ByteBuffer) {
            value = Utils.toArray((ByteBuffer) value);
        }
        if (value instanceof byte[]) {
            return Decimal.toLogical(toSchema, (byte[]) value);
        }
        if (value instanceof BigDecimal) {
            return (BigDecimal) value;
        }
        if (value instanceof Number) {
            // Not already a decimal, so treat it as a double ...
            double converted = ((Number) value).doubleValue();
            return BigDecimal.valueOf(converted);
        }
        if (value instanceof String) {
            return new BigDecimal(value.toString());
        }
        throw new DataException("Unable to convert " + value + " (" + value.getClass() + ") to " + toSchema);
    }
Convert the value to the desired type.

@param toSchema   the schema for the desired type; may not be null
@param fromSchema the schema for the supplied value; may be null if not known
@return the converted value; null if the passed-in schema was optional, and the input value was null.
@throws DataException if the value could not be converted to the desired type
connect/api/src/main/java/org/apache/kafka/connect/data/Values.java