// 定义实体转json需要方法
Product product = new Product();
GsonBuilder gb = new GsonBuilder();
gb.registerTypeAdapter(java.util.Date.class, new DateSerializer()).setDateFormat(DateFormat.LONG);
Gson gson = gb.create();
String str = gson.toJson(product)
//String 转 实体累
Gson gson = new Gson();
String strOrderInfo = request.getParameter("orderInfo");
BaoJiaOrderEntity orderEntity = gson.fromJson(strOrderInfo, BaoJiaOrderEntity.class);
//String 转 MAP
String req;
Gson josn = new Gson();
第一种: Map mapOrder = josn.fromJson(req, Map.class);
第二种:Map<String, String> resultMap2 = josn.fromJson( jsonStr, new TypeToken<Map<String, String>>() { }.getType());
注意事项:定义map时定义为Map<String, Object>确实会将3,转为3.0 定义为Map<String, String>就可以了。