package com.wecloud.im.sdk.internal;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.wecloud.im.sdk.common.ApiResult;
import com.wecloud.im.sdk.exception.WecloudImException;

/**
 *
 * @Author luozh
 * @Date 2022年04月15日 20:40
 * @Version 1.0
 */
public class ResponseParser {

    /**
     * Converts the result from stream to a java object.
     *
     * @param jsonResult
     */
    public static Object parse(String jsonResult) {
        TypeReference<ApiResult<Object>> typeRef = new TypeReference<ApiResult<Object>>() {
        };
        ApiResult<Object> apiResult = (ApiResult<Object>) JSON.parseObject(jsonResult, typeRef);
        // 判断apiResult
        if (!(apiResult.getCode() == 200)) {
            throw new WecloudImException(apiResult.getCode(), apiResult.getMessage());
        }
        return apiResult.getData();
    }
}
