Help with a compile error

14 views
Skip to first unread message

lew...@gmail.com

unread,
Aug 30, 2013, 6:55:45 PM8/30/13
to uses...@googlegroups.com
I added a question to Stack Overflow regarding a compile error that I am getting in some code.  If any of you are interested in getting the credit on SO.

http://stackoverflow.com/questions/18542177/no-json-formatter-found-for-type

The question here in the body of the message to be complete:

I added the DataNode as a List property of itself and started getting the following compile error. Is it possible to have a property of the class it is in?

I am getting a compile error:

ItemInquiry.scala:21: No Json formatter found for type List[models.DataNode]. Try to implement an implicit Format for this type. [error] (__ \ "dataNodes" ).format[List[DataNode]]


package models

import play.api.libs.json._
import play.api.libs.functional.syntax._


case class ItemSearchResult(criteria: String, site: String, searchTime: Int, exact: Boolean, searchResults: List[Item])

case class Item(name: String, upc: String, description: String, dataNodes: List[DataNode])

case class DataNode(typeVal: String, title: String, subTitle: String, requiredRole: String, dataNodes: List[DataNode])


object ItemSearchResult {

  implicit val dataNode = (
    (__ \ "type"        ).format[String] and
    (__ \ "title"       ).format[String] and
    (__ \ "requiredRole").format[String] and
    (__ \ "subTitle"    ).format[String] and
    (__ \ "dataNodes"   ).format[List[DataNode]]
   )(DataNode.apply _, unlift(DataNode.unapply _))

  implicit val item = ((__ \ "name").format[String] and
    (__ \ "upc").format[String] and
    (__ \ "description").format[String] and
    (__ \ "dataNodes").format[List[DataNode]])(Item.apply _, unlift(Item.unapply _))

  implicit val itemSearchResult = (
    (__ \ "criteria").format[String] and
    (__ \ "site").format[String] and
    (__ \ "searchTime").format[Int] and
    (__ \ "exact").format[Boolean] and
    (__ \ "searchResults").format[List[Item]])(ItemSearchResult.apply _, unlift(ItemSearchResult.unapply _))

//  implicit val itemSearchResultReads = Json.reads[ItemSearchResult]
//  implicit val itemSearchResultWrites = Json.writes[ItemSearchResult]
//
//  implicit val itemReads = Json.reads[Item]
//  implicit val itemWrites = Json.writes[Item]
//
  implicit val dataNodeReads = Json.reads[DataNode]
  implicit val dataNodeWrites = Json.writes[DataNode]

//  implicit val itemSearchResultWrites: Writes[ItemSearchResult] = (
//    (JsPath \ "criteria").write[String] and
//    (JsPath \ "site").write[String] and
//    (JsPath \ "searchTime").write[Double] and
//    (JsPath \ "exact").write[Boolean] and
//    (JsPath \ "searchResults").write[List[Item]]
//    )(unlift(ItemSearchResult.unapply))
//
//  implicit val itemWrites: Writes[Item] = (
//    (JsPath \ "name").write[String] and
//    (JsPath \ "upc").write[String] and
//    (JsPath \ "description").write[String] and
//    (JsPath \ "dataNodes").write[List[DataNode]]
//    )(unlift(Item.unapply))
//
//  implicit val dataNodeWrites: Writes[DataNode] = (
//    (JsPath \ "type").write[String] and
//      (JsPath \ "title").write[String] and
//      (JsPath \ "subTitle").write[String]
//    )(unlift(DataNode.unapply))
}

Reply all
Reply to author
Forward
0 new messages