com.alibaba.dubbo.common.utils.PojoUtils Java Examples

The following examples show how to use com.alibaba.dubbo.common.utils.PojoUtils. 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: 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 #2
Source File: JsonObjectInput.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public <T> T readObject(Class<T> cls) throws IOException, ClassNotFoundException {
    Object value = readObject();
    return (T) PojoUtils.realize(value, cls);
    /*try {
        return JSON.parse(readLine(), cls);
    } catch (ParseException e) {
        throw new IOException(e.getMessage());
    }*/
}
 
Example #3
Source File: JsonObjectInput.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public <T> T readObject(Class<T> cls) throws IOException, ClassNotFoundException {
    Object value = readObject();
    return (T) PojoUtils.realize(value, cls);
    /*try {
        return JSON.parse(readLine(), cls);
    } catch (ParseException e) {
        throw new IOException(e.getMessage());
    }*/
}
 
Example #4
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 #5
Source File: JsonObjectInput.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public <T> T readObject(Class<T> cls) throws IOException, ClassNotFoundException {
    Object value = readObject();
    return (T) PojoUtils.realize(value, cls);
    /*try {
        return JSON.parse(readLine(), cls);
    } catch (ParseException e) {
        throw new IOException(e.getMessage());
    }*/
}
 
Example #6
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 #7
Source File: MockInvoker.java    From dubbo-2.6.5 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);
//            json对象
        } else if (mock.startsWith("{")) {
            value = JSON.parseObject(mock, Map.class);
//            json数组
        } else if (mock.startsWith("[")) {
            value = JSON.parseObject(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 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 #9
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 #10
Source File: JsonObjectInput.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public <T> T readObject(Class<T> cls) throws IOException, ClassNotFoundException {
    Object value = readObject();
    return (T) PojoUtils.realize(value, cls);
    /*try {
        return JSON.parse(readLine(), cls);
    } catch (ParseException e) {
        throw new IOException(e.getMessage());
    }*/
}
 
Example #11
Source File: FastJsonObjectInput.java    From dubbox-hystrix with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public <T> T readObject(Class<T> cls, Type type) throws IOException,ClassNotFoundException
{
    Object value = readObject(cls);
    return (T) PojoUtils.realize(value, cls, type);
}
 
Example #12
Source File: FastJsonObjectInput.java    From dubbox with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public <T> T readObject(Class<T> cls, Type type) throws IOException,ClassNotFoundException
{
    Object value = readObject(cls);
    return (T) PojoUtils.realize(value, cls, type);
}
 
Example #13
Source File: JsonObjectInput.java    From dubbox with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public <T> T readObject(Class<T> cls, Type type) throws IOException,ClassNotFoundException
{
    Object value = readObject();
    return (T) PojoUtils.realize(value, cls, type);
}
 
Example #14
Source File: FastJsonObjectInput.java    From dubbox with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public <T> T readObject(Class<T> cls, Type type) throws IOException,ClassNotFoundException
{
    Object value = readObject(cls);
    return (T) PojoUtils.realize(value, cls, type);
}
 
Example #15
Source File: JsonObjectInput.java    From dubbox with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public <T> T readObject(Class<T> cls, Type type) throws IOException,ClassNotFoundException
{
    Object value = readObject();
    return (T) PojoUtils.realize(value, cls, type);
}
 
Example #16
Source File: JsonObjectInput.java    From dubbox-hystrix with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public <T> T readObject(Class<T> cls, Type type) throws IOException,ClassNotFoundException
{
    Object value = readObject();
    return (T) PojoUtils.realize(value, cls, type);
}
 
Example #17
Source File: FastJsonObjectInput.java    From dubbox with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public <T> T readObject(Class<T> cls, Type type) throws IOException,ClassNotFoundException
{
    Object value = readObject(cls);
    return (T) PojoUtils.realize(value, cls, type);
}
 
Example #18
Source File: JsonObjectInput.java    From dubbox with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public <T> T readObject(Class<T> cls, Type type) throws IOException,ClassNotFoundException
{
    Object value = readObject();
    return (T) PojoUtils.realize(value, cls, type);
}
 
Example #19
Source File: FastJsonObjectInput.java    From dubbo-2.6.5 with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public <T> T readObject(Class<T> cls, Type type) throws IOException, ClassNotFoundException {
    Object value = readObject(cls);
    return (T) PojoUtils.realize(value, cls, type);
}