java String 和ArrayList转换 换化

------------------------------------------------------------

String转为JSON对象:
String Token = URLEncoder.encode(token, "UTF-8");
String requestUrl = url + "?token=" + Token;
String response = HttpUtils.post(requestUrl);
JSONObject responseJson = JSONUtils.parseObject(response, JSONObject.class);
JSONArray dataArray = responseJson.getJSONArray("data");

JSON对象中取JSON数组:
JSONObject responseJson = JSONUtils.parseObject(response, JSONObject.class);
JSONArray dataArray = responseJson.getJSONArray("data");

------------------------------------------------------------

[Ljava.lang.String; cannot be cast to java.util.List

原因:

Map<String, Object> parameters = (Map<String, Object>) jsonResult.getData();

parameters 参数中refrenceIds 是个string

(比如:"refrenceIds": ["1438647705516691456", "1436069122789134336"],)

下步代码:

List<Long> refrenceIds = (List<Long>) MapUtils.getObject(parameters, SystemConst.REFRENCEIDS);

就会转换报错

解决:

@Override
public int submitCheckBatchAgreeOrder(Map<String, Object> parameters) throws Exception {
    //List<Long> refrenceIds = (List<Long>) MapUtils.getObject(parameters, SystemConst.REFRENCEIDS);
    List<Long> refrenceIds = ArraylistUtils.getLongList((String[]) MapUtils.getObject(parameters, SystemConst.REFRENCEIDS));
    parameters.put(SystemConst.REFRENCEIDS, refrenceIds);
    if (CollectionUtils.isEmpty(refrenceIds)){
        return NumberUtils.INTEGER_ZERO;
    }
    return agreeOrderDao.submitCheckBatchAgreeOrder(parameters);
}

------------------------------------------------------------

实体类转Map

Map<String, Object> parameters = CglibUtils.beanToMap(request);

------------------------------------------------------------

将指定的字符串数组转化为List<Long>
public static List<Long> getLongList(String[] stringArray)
{
    if (ArrayUtils.getLength(stringArray) == NumberUtils.INTEGER_ZERO)
    {
        return null;
    }
    Set<Long> set = Sets.newHashSetWithExpectedSize(stringArray.length);
    for (String str : stringArray)
    {
        try
        {
            set.add(Long.parseLong(str));
        }
        catch (NumberFormatException ex)
        {
            log.error("编号格式有误---{}", str);
            return null;
        }
    }
    return new ArrayList<>(set);
}

------------------------------------------------------------