简略代码: //生成较大的json List list = new ArrayList(); for (int i = 0; i < 500000; i++) { JsonObject obj = new JsonObject(); obj.setId(i); obj.setName("name" + String.valueOf(i)); list.add(obj); }
Gson gson = new GsonBuilder().create(); String str = gson.toJson(list);
//1,gson解析 long start1 = System.currentTimeMillis(); List l = gson.fromJson(str, new TypeToken>() { }.getType()); System.out.println("gson time elapse:" + (System.currentTimeMillis() - start1)); System.out.println(l.size());
//2,jackson解析 ObjectMapper mapper = new ObjectMapper(); long start2 = System.currentTimeMillis(); List l2 = mapper.readValue(str, new TypeReference>() { }); System.out.println("jackson time elapse:" + (System.currentTimeMillis() - start2)); System.out.println(l2.size());