public static final Long castToLong(Object value) {
        if (value == null) {
            return null;
        }

        if (value instanceof Number) {
            return ((Number) value).longValue();
        }

        if (value instanceof String) {
            String strVal = (String) value;
            if (strVal.length() == 0) {
                return null;
            }

            try {
                return Long.parseLong(strVal);
            } catch (NumberFormatException ex) {
                //
            }
        }

        throw new JSONException("can not cast to long, value : " + value);
    }
from fastjson
@author Robert HG (254963746@qq.com) on 11/21/15.
lts-core/src/main/java/com/github/ltsopensource/core/json/TypeUtils.java