当前位置: 首页>>代码示例>>Java>>正文


Java PojoUtils类代码示例

本文整理汇总了Java中com.alibaba.dubbo.common.utils.PojoUtils的典型用法代码示例。如果您正苦于以下问题:Java PojoUtils类的具体用法?Java PojoUtils怎么用?Java PojoUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PojoUtils类属于com.alibaba.dubbo.common.utils包,在下文中一共展示了PojoUtils类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parseMockValue

import com.alibaba.dubbo.common.utils.PojoUtils; //导入依赖的package包/类
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;
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:30,代码来源:MockInvoker.java

示例2: readObject

import com.alibaba.dubbo.common.utils.PojoUtils; //导入依赖的package包/类
@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());
    }*/
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:11,代码来源:JsonObjectInput.java

示例3: invoke

import com.alibaba.dubbo.common.utils.PojoUtils; //导入依赖的package包/类
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
    Result result = invoker.invoke(invocation);
    if (! invocation.getMethodName().startsWith("$") && ! result.hasException()) {
        Object value = result.getValue();
        if (value != null) {
            try {
                Method method = invoker.getInterface().getMethod(invocation.getMethodName(), invocation.getParameterTypes());
                Class<?> type = method.getReturnType();
                Object newValue;
                String serialization = invoker.getUrl().getParameter(Constants.SERIALIZATION_KEY); 
                if ("json".equals(serialization)
                        || "fastjson".equals(serialization)){
                    Type gtype = method.getGenericReturnType();
                    newValue = PojoUtils.realize(value, type, gtype);
                } else if (! type.isInstance(value)) {
                    newValue = PojoUtils.isPojo(type)
                        ? PojoUtils.realize(value, type) 
                        : CompatibleTypeUtils.compatibleTypeConvert(value, type);
                    
                } else {
                    newValue = value;
                }
                if (newValue != value) {
                    result = new RpcResult(newValue);
                }
            } catch (Throwable t) {
                logger.warn(t.getMessage(), t);
            }
        }
    }
    return result;
}
 
开发者ID:xingmima,项目名称:dubbos,代码行数:33,代码来源:CompatibleFilter.java

示例4: parseMockValue

import com.alibaba.dubbo.common.utils.PojoUtils; //导入依赖的package包/类
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;
}
 
开发者ID:linux-china,项目名称:dubbo3,代码行数:30,代码来源:MockInvoker.java

示例5: invoke

import com.alibaba.dubbo.common.utils.PojoUtils; //导入依赖的package包/类
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
    Result result = invoker.invoke(invocation);
    if (! invocation.getMethodName().startsWith("$") && ! result.hasException()) {
        Object value = result.getValue();
        if (value != null) {
            try {
                Method method = invoker.getInterface().getMethod(invocation.getMethodName(), invocation.getParameterTypes());
                Class<?> type = method.getReturnType();
                Object newValue;
                String serialization = invoker.getUrl().getParameter(Constants.SERIALIZATION_KEY); 
                if ("json".equals(serialization)){
                    Type gtype = method.getGenericReturnType();
                    newValue = PojoUtils.realize(value, type, gtype);
                } else if (! type.isInstance(value)) {
                    newValue = PojoUtils.isPojo(type)
                        ? PojoUtils.realize(value, type) 
                        : CompatibleTypeUtils.compatibleTypeConvert(value, type);
                    
                } else {
                    newValue = value;
                }
                if (newValue != value) {
                    result = new RpcResult(newValue);
                }
            } catch (Throwable t) {
                logger.warn(t.getMessage(), t);
            }
        }
    }
    return result;
}
 
开发者ID:linux-china,项目名称:dubbo3,代码行数:32,代码来源:CompatibleFilter.java

示例6: parseMockValue

import com.alibaba.dubbo.common.utils.PojoUtils; //导入依赖的package包/类
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;
}
 
开发者ID:nince-wyj,项目名称:jahhan,代码行数:31,代码来源:MockInvoker.java

示例7: invoke

import com.alibaba.dubbo.common.utils.PojoUtils; //导入依赖的package包/类
public Result invoke(Invoker<?> invoker, Invocation invocation) throws JahhanException {
	Result result = invoker.invoke(invocation);
	if (!invocation.getMethodName().startsWith("$") && !result.hasException()) {
		Object value = result.getValue();
		if (value != null) {
			try {
				Method method = invoker.getInterface().getMethod(invocation.getMethodName(),
						invocation.getParameterTypes());
				Class<?> type = method.getReturnType();
				Object newValue;
				String serialization = invoker.getUrl().getParameter(Constants.SERIALIZATION_KEY);
				if ("json".equals(serialization) || "fastjson".equals(serialization)) {
					Type gtype = method.getGenericReturnType();
					newValue = PojoUtils.realize(value, type, gtype);
				} else if (!type.isInstance(value)) {
					newValue = PojoUtils.isPojo(type) ? PojoUtils.realize(value, type)
							: CompatibleTypeUtils.compatibleTypeConvert(value, type);

				} else {
					newValue = value;
				}
				if (newValue != value) {
					result = new RpcResult(newValue);
				}
			} catch (Throwable t) {
				log.warn(t.getMessage(), t);
			}
		}
	}
	return result;
}
 
开发者ID:nince-wyj,项目名称:jahhan,代码行数:32,代码来源:CompatibleFilter.java


注:本文中的com.alibaba.dubbo.common.utils.PojoUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。