Java Code Examples for com.alibaba.dubbo.common.json.JSON#parse()

The following examples show how to use com.alibaba.dubbo.common.json.JSON#parse() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OrderControllerImpl.java    From SpringBoot-Dubbo-Docker-Jenkins with Apache License 2.0 6 votes vote down vote up
private void transferProdIdCountJson(OrderInsertReq orderInsertReq) {
    if (orderInsertReq != null && StringUtils.isNotEmpty(orderInsertReq.getProdIdCountJson())) {
        try {
            Map<String, Long> prodIdCountMapPre = JSON.parse(orderInsertReq.getProdIdCountJson(), Map.class);
            Map<String, Integer> prodIdCountMap = Maps.newHashMap();
            if (prodIdCountMapPre.size() > 0) {
                for (String key : prodIdCountMapPre.keySet()) {
                    prodIdCountMap.put(key, (Integer) prodIdCountMapPre.get(key).intValue());
                }
            }
            orderInsertReq.setProdIdCountMap(prodIdCountMap);
        } catch (ParseException e) {
            throw new CommonBizException(ExpCodeEnum.JSONERROR);
        }
    }

}
 
Example 2
Source File: JsonObjectInput.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public Object readObject() throws IOException, ClassNotFoundException {
    try {
        String json = readLine();
        if (json.startsWith("{")) {
            return JSON.parse(json, Map.class);
        } else {
            json = "{\"value\":" + json + "}";
            
            @SuppressWarnings("unchecked")
            Map<String, Object> map = JSON.parse(json, Map.class);
            return map.get("value");
        }
    } catch (ParseException e) {
        throw new IOException(e.getMessage());
    }
}
 
Example 3
Source File: JsonObjectInput.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
public Object readObject() throws IOException, ClassNotFoundException {
    try {
        String json = readLine();
        if (json.startsWith("{")) {
            return JSON.parse(json, Map.class);
        } else {
            json = "{\"value\":" + json + "}";
            
            @SuppressWarnings("unchecked")
            Map<String, Object> map = JSON.parse(json, Map.class);
            return map.get("value");
        }
    } catch (ParseException e) {
        throw new IOException(e.getMessage());
    }
}
 
Example 4
Source File: JsonObjectInput.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public Object readObject() throws IOException, ClassNotFoundException {
    try {
        String json = readLine();
        if (json.startsWith("{")) {
            return JSON.parse(json, Map.class);
        } else {
            json = "{\"value\":" + json + "}";
            
            @SuppressWarnings("unchecked")
            Map<String, Object> map = JSON.parse(json, Map.class);
            return map.get("value");
        }
    } catch (ParseException e) {
        throw new IOException(e.getMessage());
    }
}
 
Example 5
Source File: JsonObjectInput.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public Object readObject() throws IOException, ClassNotFoundException {
    try {
        String json = readLine();
        if (json.startsWith("{")) {
            return JSON.parse(json, Map.class);
        } else {
            json = "{\"value\":" + json + "}";
            
            @SuppressWarnings("unchecked")
            Map<String, Object> map = JSON.parse(json, Map.class);
            return map.get("value");
        }
    } catch (ParseException e) {
        throw new IOException(e.getMessage());
    }
}
 
Example 6
Source File: MainAction.java    From DevToolBox with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void createShowDoc(String respBody, HttpRequestData.Request req) throws Exception {
    String tmp = respBody.startsWith("\"") ? respBody.substring(1, respBody.length() - 1) : respBody;
    JsonObject json = gson.fromJson(tmp, JsonObject.class);
    StringBuilder sb = new StringBuilder();
    String urlstr = req.getUrl();
    String[] adds = urlstr.split("/");
    int idx = urlstr.indexOf(adds[3]);
    sb.append("**简要描述:**\n\n- \n\n**请求URL:**\n\n- ` ").append(urlstr.substring(idx));
    sb.append(" `\n\n**请求方式:**\n\n- ").append(req.getMethod()).append(" \n\n**参数:** \n\n|参数名|必选|类型|说明|\n|:----|:---|:-----|-----|\n");
    String param = req.getBody();

    if (param != null && !param.trim().isEmpty()) {
        if ((param.startsWith("{") || param.startsWith("[")) && (param.endsWith("{") || param.endsWith("["))) {
            JsonObject jo = JSON.parse(param, JsonObject.class
            );
            jo.entrySet().forEach((entry) -> {
                removeArrayEle(entry.getValue());
            });
            analysisJsonStr(sb, jo);
        } else {
            String[] pms = param.split("&");
            for (String pm : pms) {
                sb.append("|").append(pm.split("=")[0]).append("|  |String|  |\n");
            }
        }
    }
    json.entrySet().forEach((entry) -> {
        removeArrayEle(entry.getValue());
    });
    sb.append("**返回示例**\n\n```\n").append(Formatter.formatJson(json.toString())).append("\n```\n\n**返回参数说明** \n\n|参数名|类型|说明|备注|\n|:-----|:-----|-----| |\n");
    analysisJsonStr(sb, json);
    sb.append(" **备注** \n\n- 更多返回错误代码请看首页的错误代码描述");
    mc.showDoc.setText(sb.toString());
}
 
Example 7
Source File: MockInvoker.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public static Object parseMockValue(String mock, Type[] returnTypes) throws Exception {
    Object value = null;
    if ("empty".equals(mock)) {
        value = ReflectUtils.getEmptyObject(returnTypes != null && returnTypes.length > 0 ? (Class<?>)returnTypes[0] : null);
    } else if ("null".equals(mock)) {
        value = null;
    } else if ("true".equals(mock)) {
        value = true;
    } else if ("false".equals(mock)) {
        value = false;
    } else if (mock.length() >=2 && (mock.startsWith("\"") && mock.endsWith("\"")
            || mock.startsWith("\'") && mock.endsWith("\'"))) {
        value = mock.subSequence(1, mock.length() - 1);
    } else if (returnTypes !=null && returnTypes.length >0 && returnTypes[0] == String.class) {
        value = mock;
    } else if (StringUtils.isNumeric(mock)) {
        value = JSON.parse(mock);
    }else if (mock.startsWith("{")) {
        value = JSON.parse(mock, Map.class);
    } else if (mock.startsWith("[")) {
        value = JSON.parse(mock, List.class);
    } else {
        value = mock;
    }
    if (returnTypes != null && returnTypes.length > 0) {
        value = PojoUtils.realize(value, (Class<?>)returnTypes[0], returnTypes.length > 1 ? returnTypes[1] : null);
    }
    return value;
}
 
Example 8
Source File: MockInvoker.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
public static Object parseMockValue(String mock, Type[] returnTypes) throws Exception {
    Object value = null;
    if ("empty".equals(mock)) {
        value = ReflectUtils.getEmptyObject(returnTypes != null && returnTypes.length > 0 ? (Class<?>)returnTypes[0] : null);
    } else if ("null".equals(mock)) {
        value = null;
    } else if ("true".equals(mock)) {
        value = true;
    } else if ("false".equals(mock)) {
        value = false;
    } else if (mock.length() >=2 && (mock.startsWith("\"") && mock.endsWith("\"")
            || mock.startsWith("\'") && mock.endsWith("\'"))) {
        value = mock.subSequence(1, mock.length() - 1);
    } else if (returnTypes !=null && returnTypes.length >0 && returnTypes[0] == String.class) {
        value = mock;
    } else if (StringUtils.isNumeric(mock)) {
        value = JSON.parse(mock);
    }else if (mock.startsWith("{")) {
        value = JSON.parse(mock, Map.class);
    } else if (mock.startsWith("[")) {
        value = JSON.parse(mock, List.class);
    } else {
        value = mock;
    }
    if (returnTypes != null && returnTypes.length > 0) {
        value = PojoUtils.realize(value, (Class<?>)returnTypes[0], returnTypes.length > 1 ? returnTypes[1] : null);
    }
    return value;
}
 
Example 9
Source File: MockInvoker.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
public static Object parseMockValue(String mock, Type[] returnTypes) throws Exception {
    Object value;
    if ("empty".equals(mock)) {
        value = ReflectUtils.getEmptyObject(returnTypes != null && returnTypes.length > 0 ? (Class<?>) returnTypes[0] : null);
    } else if ("null".equals(mock)) {
        value = null;
    } else if ("true".equals(mock)) {
        value = true;
    } else if ("false".equals(mock)) {
        value = false;
    } else if (mock.length() >= 2 && (mock.startsWith("\"") && mock.endsWith("\"")
            || mock.startsWith("\'") && mock.endsWith("\'"))) {
        value = mock.subSequence(1, mock.length() - 1);
    } else if (returnTypes != null && returnTypes.length > 0 && returnTypes[0] == String.class) {
        value = mock;
    } else if (StringUtils.isNumeric(mock)) {
        value = JSON.parse(mock);
    } else if (mock.startsWith("{")) {
        value = JSON.parse(mock, Map.class);
    } else if (mock.startsWith("[")) {
        value = JSON.parse(mock, List.class);
    } else {
        value = mock;
    }
    if (returnTypes != null && returnTypes.length > 0) {
        value = PojoUtils.realize(value, (Class<?>) returnTypes[0], returnTypes.length > 1 ? returnTypes[1] : null);
    }
    return value;
}
 
Example 10
Source File: MockInvoker.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public static Object parseMockValue(String mock, Type[] returnTypes) throws Exception {
    Object value = null;
    if ("empty".equals(mock)) {
        value = ReflectUtils.getEmptyObject(returnTypes != null && returnTypes.length > 0 ? (Class<?>)returnTypes[0] : null);
    } else if ("null".equals(mock)) {
        value = null;
    } else if ("true".equals(mock)) {
        value = true;
    } else if ("false".equals(mock)) {
        value = false;
    } else if (mock.length() >=2 && (mock.startsWith("\"") && mock.endsWith("\"")
            || mock.startsWith("\'") && mock.endsWith("\'"))) {
        value = mock.subSequence(1, mock.length() - 1);
    } else if (returnTypes !=null && returnTypes.length >0 && returnTypes[0] == String.class) {
        value = mock;
    } else if (StringUtils.isNumeric(mock)) {
        value = JSON.parse(mock);
    }else if (mock.startsWith("{")) {
        value = JSON.parse(mock, Map.class);
    } else if (mock.startsWith("[")) {
        value = JSON.parse(mock, List.class);
    } else {
        value = mock;
    }
    if (returnTypes != null && returnTypes.length > 0) {
        value = PojoUtils.realize(value, (Class<?>)returnTypes[0], returnTypes.length > 1 ? returnTypes[1] : null);
    }
    return value;
}
 
Example 11
Source File: MockInvoker.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public static Object parseMockValue(String mock, Type[] returnTypes) throws Exception {
    Object value = null;
    if ("empty".equals(mock)) {
        value = ReflectUtils.getEmptyObject(returnTypes != null && returnTypes.length > 0 ? (Class<?>)returnTypes[0] : null);
    } else if ("null".equals(mock)) {
        value = null;
    } else if ("true".equals(mock)) {
        value = true;
    } else if ("false".equals(mock)) {
        value = false;
    } else if (mock.length() >=2 && (mock.startsWith("\"") && mock.endsWith("\"")
            || mock.startsWith("\'") && mock.endsWith("\'"))) {
        value = mock.subSequence(1, mock.length() - 1);
    } else if (returnTypes !=null && returnTypes.length >0 && returnTypes[0] == String.class) {
        value = mock;
    } else if (StringUtils.isNumeric(mock)) {
        value = JSON.parse(mock);
    }else if (mock.startsWith("{")) {
        value = JSON.parse(mock, Map.class);
    } else if (mock.startsWith("[")) {
        value = JSON.parse(mock, List.class);
    } else {
        value = mock;
    }
    if (returnTypes != null && returnTypes.length > 0) {
        value = PojoUtils.realize(value, (Class<?>)returnTypes[0], returnTypes.length > 1 ? returnTypes[1] : null);
    }
    return value;
}