码迷,mamicode.com
首页 > Web开发 > 详细

将Json转实体

时间:2018-02-06 14:11:12      阅读:259      评论:0      收藏:0      [点我收藏+]

标签:blog   app   16px   ring   pre   map   cep   actor   gen   

算了,不废话了技术分享图片

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);
  ……
}

将Json转实体

标签:blog   app   16px   ring   pre   map   cep   actor   gen   

原文地址:https://www.cnblogs.com/IceBlueBrother/p/8421758.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!