算了,不废话了
protected static ObjectMapper mapper = new ObjectMapper();
//转一个
public <S> S getRequestParams(String json, Class<S> membersClazzs)
throws JsonParseException, JsonMappingException, IOException {
return mapper.readValue(json, membersClazzs);
}
//转多个
public static <S> S getRequestParams(String json, Class<?> collectionsClass,
Class<?>... membersClazzs) throws JsonParseException,
JsonMappingException, IOException {
return mapper.readValue(json, mapper.getTypeFactory().constructParametricType(collectionsClass, membersClazzs));
}
//调用转换方法
public voidTest(@RequestParam("entityJSON") StringentityJSON,……){
……
Entity entity= getRequestParams(entityJSON,Entity.class);
……
}