jacson 将json字符串转换为list

springmvc 很蛋疼地不支持list传输,所以在项目中先把list转换为了json字符串,再在后台接收  用jacson将json字符串转换为指定泛型的list

直接上代码

ObjectMapper mapper = new ObjectMapper();
JavaType javaType = mapper.getTypeFactory().constructParametricType(ArrayList.class, String.class);
List<String> list = new ArrayList<String>();
  try {
	list =  (List<String>)mapper.readValue(roleLocation, javaType);
	} catch (JsonParseException e) {
		e.printStackTrace();
	} catch (JsonMappingException e) {
		e.printStackTrace();
	} catch (IOException e) {
		e.printStackTrace();
} 

  其中 String.class是我要转换的list的泛型类型 ArrayList是我要转换成的List类型

原文地址:https://www.cnblogs.com/yongde/p/3314566.html