All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.dingtalk.baymax.framework.sdk.mercury.util.ServiceResultUtils Maven / Gradle / Ivy

There is a newer version: 1.0.2
Show newest version
package com.dingtalk.baymax.framework.sdk.mercury.util;

import java.util.Map;
import java.util.Objects;

/**
 * @Author xiaoyan
 * @Date 2023-07-21 20:56:33
 */
public class ServiceResultUtils {

    public static boolean isSuccess(Object serviceResult) {
        if (Objects.isNull(serviceResult)) {
            return false;
        }

        if (!Map.class.isAssignableFrom(serviceResult.getClass())) {
            return false;
        }

        Map map = Map.class.cast(serviceResult);
        Object success = map.get("success");
        if (Objects.isNull(success)) {
            return false;
        }

        return Boolean.parseBoolean(success.toString());
    }

    public static Object getResult(Object serviceResult) {
        if (Objects.isNull(serviceResult)) {
            return null;
        }

        Map map = Map.class.cast(serviceResult);
        return map.get("result");
    }

    public static Object getErrorCode(Object serviceResult) {
        if (Objects.isNull(serviceResult)) {
            return null;
        }

        Map map = Map.class.cast(serviceResult);
        return map.get("errorCode");
    }

    public static Object getErrorMsg(Object serviceResult) {
        if (Objects.isNull(serviceResult)) {
            return null;
        }

        Map map = Map.class.cast(serviceResult);
        return map.get("errorMsg");
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy