Ok, firstly I am new to posting questions here, so go easy on me.
I feel like I have scowered the interwebs to figure this out, and I sure must be slow because I just cant get it right - I know this should be simple.
I have a class:
class Produce extends LongKeyedMapper[Produce] with IdPK {
def getSingleton = Produce
object producetype extends MappedString(this,20)
object name extends MappedString(this,20)
object description extends MappedString(this,255)
}
The object has a few helper methods and some other things I have pieced together to try to get this to work:
object Produce extends Produce with LongKeyedMetaMapper[Produce] {
private implicit val formats = net.liftweb.json.DefaultFormats
override def fieldOrder = List(producetype, name, description)
def search(str: String): List[Produce] = {
val strLC = str.toLowerCase()
Produce.findAll(By(Produce.producetype, strLC))
}
implicit def toJson(item: Produce): JValue = Extraction.decompose(item)
implicit def toJson(items: List[Produce]): JValue = Extraction.decompose(items)
}
my rest service is doing the basic stuff and is matching with this:
serve( "api" / "item" prefix {
case "search" :: q JsonGet _ =>
(for {
searchString <- q ::: S.params("q")
item <- Produce.search(searchString)
} yield item): JValue
})
So to my delight, it worked, i got it matching.. and returning Json, the problem is: Let's say I have 3 rows in the DB with producetype: a, if I call the service with 'a' it returns:
[{
},{
},{
}]
So it is returning, it just isn't serializing any of the data... I have tried overloading unapply methods and trying to figure out if case classes could help me out - but it isn't clicking n my feeble mind. Any help?