Admin 是一个 继承了Model类,我遇到问题,Admin 作为输入参数,在通过 反射method.invoke() 调用中无法获取转换的值,其它几个输入类,不管是Map还是 javaBean都可以很好通过method.invoke 反射动态调用执行。我现在想实现采用jsonrpc调用Service.不太了解怎么将json数据转成对应model实例以及作为 invoke参数输入?
{
"jsonrpc": "2.0",
"method": "admin.update",
"params":[{"username":"bbbb","role":"bbbbb","id":1}],
"id":1
}
public boolean update(Admin admin); public boolean update(Map<String, String> map); public boolean update(AdminBean bean);
//TODO 这段代码造成封装有问题 convertedParams = convertJsonToParameters(method, params); if (convertedParameterTransformer != null) { convertedParams = convertedParameterTransformer.transformConvertedParameters(target, convertedParams); } result = method.invoke(target, convertedParams);
private Object[] convertJsonToParameters(Method m, List<JsonNode> params) throws IOException { Object[] convertedParams = new Object[params.size()]; Type[] parameterTypes = m.getGenericParameterTypes(); /**********start guoenzhou h2017-11-16 04:45 对于输入参数是jinfal 模型无法获取到值**************/ for (int i = 0; i < parameterTypes.length; i++) { JsonParser paramJsonParser = mapper.treeAsTokens(params.get(i)); JavaType paramJavaType = mapper.getTypeFactory().constructType(parameterTypes[i]); convertedParams[i] = mapper.readValue(paramJsonParser, paramJavaType);//在参数向类注入参数时不行 } //for (int i = 0; i < parameterTypes.length; i++) { //JsonParser paramJsonParser = mapper.treeAsTokens(params.get(i)); //JavaType paramJavaType = mapper.getTypeFactory().constructType(parameterTypes[i]); //convertedParams[i] = mapper.readValue(paramJsonParser, paramJavaType);//在参数向类注入参数时不行 //} /**********end guoenzhou 2017-11-16 04:45 对于输入参数是jinfal 模型无法获取到值**************/ return convertedParams; }
项目:JFinal
2:me.setJsonFactory(new MixedJsonFactory())
3:Json.getJson().parse(jsonString, Admin.class)