fastjson复杂json转换为java对象

最近从redis里面取数据的时候发现有一个结构时较为复杂的json,开始还想着要用反射机制将json转换为对象。最后经过查阅很多文档fastjson性能很好,经过很多实验终于将json转换为对应java bean了。
json:

{
  "areaInit": false,
  "corpId": 211,
  "inCustomAreaList": [
    {
      "areaAcReage": 0.0,
      "areaId": 90,
      "corpId": 1,
      "createdUserId": 0,
      "inlayer": 0,
      "isValid": 1,
      "modifiedUserId": 0,
      "orgId": 0,
      "range": 0,
      "shareMode": 0,
      "typeId": 0
    }
  ],
  "preGPSData": {
    "VehicleID": 2762,
    "statusStr": "ACC关,3D定位,天线正常",
    "GpsTime": 1626008713000,
    "Wid": "14548985459",
    "Lon": 113.5479520,
    "Lat": 23.1982880,
    "Speed": 0,
    "Direction": 145,
    "Odometer": 388058.50,
    "Height": 39,
    "ACCStatus": 1,
    "LineStatus": 1,
    "LoStatus": 3,
    "Status": "",
    "UpdateDate": 1626008714000
  },
  "vehicleID": 2763
}

转换代码

JSONObject parse = JSON.parseObject(parseValue);
VehicleTrajectoryDTO vehicleTrajectoryDTO = parse.toJavaObject(VehicleTrajectoryDTO.class);

只要两行就搞定。

你可能感兴趣的:(Java,Json,fastjson,json,java)