/
Tweet.scala
30 lines (26 loc) · 871 Bytes
/
Tweet.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package com.retwis.model
import net.liftweb.json._
import net.liftweb.json.JsonAST._
import net.liftweb.json.JsonDSL._
object Tweet {
def getTweetFromJson(jsonStr: String):Tweet = {
implicit val formats = net.liftweb.json.DefaultFormats
val json = parse(jsonStr)
val id = (json \ "tweet" \ "id").extract[String]
val time = (json \ "tweet" \ "time").extract[Long]
val message = (json \ "tweet" \ "message").extract[String]
val authorId = (json \ "tweet" \ "authorId").extract[String]
return new Tweet(id, time, message, authorId)
}
}
class Tweet(val id: String, val time: Long, val message: String, val authorId: String) {
/* Serialize tweet to JSON string */
def toJson(): String = {
val json = ("tweet" ->
("id" -> id) ~
("time" -> time) ~
("message" -> message) ~
("authorId" -> authorId))
compact(JsonAST.render(json))
}
}