2016-07-22 13 views
0

クライアントからJSONデータを読み込み、解析するため、挿入メソッドを使用してテーブルに挿入できますが、Play 2.5とSlick 3.1.1の暗黙的な読み取りOption [BigDecimal]にエラーがスローされます、なぜですか?PUT関数のコントローラークラスの暗黙的な読み取りSCALAプレイフレームワーク

object RBooks {implicit val xReads: Reads[xRow] = (
    (JsPath \ "bookId").read[Option[BigDecimal]] and 
    (JsPath \ "bookName").read[Option[String]] and 
    (JsPath \ "bookDesc").read[Option[String]] and 
    (JsPath \ "enabled").read[Option[Char]] and 
    (JsPath \ "primaryBook").read[Option[Char]] and 
    (JsPath \ "bookType").read[Option[String]] and 
    (JsPath \ "bookCurrency").read[Option[String]] and 
    (JsPath \ "startDate").read[Option[java.sql.Timestamp]] and 
    (JsPath \ "endDate").read[Option[java.sql.Timestamp]] and 
    (JsPath \ "allocationsEnabled").read[Option[Char]] and 
    (JsPath \ "arrPrefix").read[Option[String]] and 
    (JsPath \ "creationDate").read[Option[java.sql.Timestamp]] and  
    (JsPath \ "createdBy").read[Option[String]] and 
    (JsPath \ "lastUpdateDate").read[Option[Timestamp]] and 
    (JsPath \ "lastUpdatedBy").read[Option[String]] 
)(slickLib.xRow.apply _) 

エラー出力Iが得る:

No Json deserializer found for type Option[BigDecimal]. Try to implement an implicit Reads or Format for this type.(xRow.apply _) this code is throwing a error: (JsPath \ "bookId").read[Option[BigDecimal]] and 

プレイScalaでは.readは、オプション[BigDecimalを]をサポートしていませんか?

+0

は、なぜあなたは 'オプション[BigDecimalの]' 'の代わりにオプションの[10進】'のしたいですか? – jwvh

+0

はい、私はOption [BigDecimal]を使用する必要があります。slickLib.xRow.apply _)は赤なしで取得します。コードを実行するとエラーが発生しますが、scalaがこの暗黙の読み取りを受け付けない理由はわかりません。 – governingcloud

答えて

-1

オプション[BigDecimal]は、プレイでサポートされていません。2.5 scala 12.11.x.別の方法は、滑らかなORMプロジェクトにjson4sのようなライブラリを使用することです。

2

read[Option[Anytype]]を使用しないでください。代わりにreadNullable[Anytype]を使用してください。 例:サポートされていないタイプの場合

(JsPath \ "bookId").readNullable[BigDecimal] 

あなたは自分のパーサを書いたりしたい入力するsuppotedタイプから変換する必要があります。たとえば、あなたはそのようなjava.sql.Timestampに対処することができます

import java.sql.Timestamp 
(__ \ 'creationDate).readNullable[Long].map(_.map(new Timestamp(_))) 
関連する問題