deserializing निम्नलिखित मामले वर्ग धारावाहिक जा करने के लिए/to/JSON से deserialized की जरूरत है कि यह देखते हुए ...कैसे अतिभारित को अस्पष्ट संदर्भ तय करने के लिए लागू होते हैं() विधि जब Json
import play.api.libs.json
import play.api.libs.functional.syntax._
trait MyTrait(s1: String, s2: String)
case class MyClass(s1: String, s2: String) extends MyTrait {
def this(t: MyTrait) = this(t.s1, t.s2)
}
object MyClass {
def apply(t: MyTrait) = new MyClass(t)
implicit val myClassJsonWrite = new Writes[MyClass] {
def writes(c: MyClass): JsValue = {
Json.obj(
"s1" -> c.s1,
"s2" -> c.s2
)
}
}
implicit val myClassJsonRead = (
(__ \ 's1).read[String] ~
(__ \ 's2).read[String]
)(MyClass.apply _)
}
... मैं हमेशा मिलता है निम्न त्रुटि संदेश:
[error] /home/j3d/Projects/test/app/models/MyClass.scala:52: ambiguous reference to overloaded definition,
[error] both method apply in object MyClass of type (s1: String, s2: String)models.MyClass
[error] and method apply in object MyClass of type (t: MyTrait)models.MyClass
[error] match expected type ?
[error] )(MyClass.apply _)
[error] ^
... क्यों संकलक अनुमान नहीं करता है सही apply
विधि? मैं इस त्रुटि को कैसे ठीक कर सकता हूं? किसी भी तरह की सहायता की सच में प्रशंसा की जाएगी। धन्यवाद।
धन्यवाद बदल सकते हैं
यह, काम करता है :-) – j3d