3
我我得到了一個錯誤:噴霧JSON解析和NullPointerException異常
spray.json.ProductFormats$class.productElement2Field NullPointerException
這裏是我的JSON deserialisation代碼:
object DomainJsonProtocol extends DefaultJsonProtocol {
implicit val loginInfoFormat = jsonFormat(LoginInfo, "userid", "email", "password", "rememberme")
implicit val requestStatusFormat = jsonFormat(RequestStatus, "status", "message")
implicit val requestHolderFormat = jsonFormat(RequestHolder, "requestStatus", "loginInfo")
}
case class RequestHolder(requestStatus : RequestStatus, loginInfo: LoginInfo) {
def this(requestStatus : RequestStatus) = this(requestStatus, null)
}
case class LoginInfo(userid: Int, email: String, password: String, rememberme: Boolean)
case class RequestStatus(status : Int, message: String)
val requestHolder = content.asJson.convertTo[RequestHolder] //The error is hereHere is
我想這可能是因爲在類的重載構造RequestHolder。
UPD: JSON的內容是:
{"requestStatus":{"status":0,"message":""},"loginInfo":{"userid":0,"email":"123","password":"123","rememberme":false}}