将mongoDB Document JSON解析为scala案例类

时间:2018-05-09 06:18:47

标签: json mongodb scala

这是我的代码 -

MongoFactory.WorkOrdercollection.find().subscribe(
  (user: Document) => println(user.toJson()),                         // onNext
  (error: Throwable) => println(s"Query failed: ${error.getMessage}"), // onError
  () => println("Done")                                               // onComplete
)

这是我的MongoDB Document JSON -

{  
   "_id":"5af153f49547a205f9798129",
   "workOrderId":"9a9e1ce8-c576-4a15-a1ff-4af780b14b7f",
   "thingId":"Mumbai_Robot_3",
   "alertId":"Alert_1",
   "description":"Robot is not in good condition",
   "contactId":"8087827108",
   "estimatedDuration":"2 Hours",
   "workOrderStatus":"CREATED",
   "lifecycleStatus":"NEW",
   "maintenancePlanId":"100",
   "createdDate":{  
      "$date":1525699800000
   },
   "updatedDate":{  
      "$date":1525781377952
   },
   "lastViewedDate":{  
      "$date":1525781377952
   },
   "suggestedMaintenanceDate":{  
      "$date":1525781377952
   },
   "startDate":{  
      "$date":1525781377952
   }
}

我在转换日期时遇到异常。 如何将此JSON字符串转换为scala案例类?

0 个答案:

没有答案