算了,不废话了
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转实体
原文地址:https://www.cnblogs.com/IceBlueBrother/p/8421758.html