json-lib 与 jackson toBean

//用 jackson 转化成bean
		System.out.println(DateUtil.getNowTimeStr("yyyy-MM-dd HH:mm:ss.sss"));
		ObjectMapper mapper = new ObjectMapper();
		File file = new File("src\\bean.json");
		for (int i = 0; i < 100000; i++) {
			User user = mapper.readValue(file, User.class);
		}
		System.out.println(DateUtil.getNowTimeStr("yyyy-MM-dd HH:mm:ss.sss"));
		
		//用 json-lib 转化成bean
		System.out.println(DateUtil.getNowTimeStr("yyyy-MM-dd HH:mm:ss.sss"));
		FileInputStream in = new FileInputStream(file);
		byte[] buff = new byte[in.available()+1];
		in.read(buff, 0, in.available());
		String str = new String(buff);
		for (int i = 0; i < 100000; i++) {
			JSONObject jsonObject = JSONObject.fromObject(str);
			User user = (User)JSONObject.toBean(jsonObject,User.class);
		}
		System.out.println(DateUtil.getNowTimeStr("yyyy-MM-dd HH:mm:ss.sss"));
 

你可能感兴趣的:(json-lib)