|
| 1 | +package com.microWorkflow.jsonScalaPerftest.rojoma |
| 2 | + |
| 3 | +import com.rojoma.json.io.JsonReader |
| 4 | +import com.rojoma.json.util.{JsonUtil, SimpleJsonCodecBuilder} |
| 5 | +import com.microWorkflow.jsonScalaPerftest.LibraryAdaptor |
| 6 | + |
| 7 | +case class User(utcOffset: Int, timeZone: String) |
| 8 | +object User { |
| 9 | + implicit val jCodec = SimpleJsonCodecBuilder[User].build( |
| 10 | + "utc_offset", _.utcOffset, |
| 11 | + "time_zone", _.timeZone |
| 12 | + ) |
| 13 | +} |
| 14 | + |
| 15 | +case class Url(indices: Seq[Int], url: String) |
| 16 | +object Url { |
| 17 | + implicit val jCodec = SimpleJsonCodecBuilder[Url].build( |
| 18 | + "indices", _.indices, |
| 19 | + "url", _.url |
| 20 | + ) |
| 21 | +} |
| 22 | + |
| 23 | +case class Hashtag(indices: Seq[Int], text: String) |
| 24 | +object Hashtag { |
| 25 | + implicit val jCodec = SimpleJsonCodecBuilder[Hashtag].build( |
| 26 | + "indices", _.indices, |
| 27 | + "text", _.text |
| 28 | + ) |
| 29 | +} |
| 30 | + |
| 31 | +case class UserMention(indices: Seq[Int], name: String) |
| 32 | +object UserMention { |
| 33 | + implicit val jCodec = SimpleJsonCodecBuilder[UserMention].build( |
| 34 | + "indices", _.indices, |
| 35 | + "name", _.name |
| 36 | + ) |
| 37 | +} |
| 38 | + |
| 39 | +case class Entities(hashtags: Seq[Hashtag], urls: Seq[Url], userMentions: Seq[UserMention]) |
| 40 | +object Entities { |
| 41 | + implicit val jCodec = SimpleJsonCodecBuilder[Entities].build( |
| 42 | + "hashtags", _.hashtags, |
| 43 | + "urls", _.urls, |
| 44 | + "user_mentions", _.userMentions |
| 45 | + ) |
| 46 | +} |
| 47 | + |
| 48 | +case class Tweet(idStr: String, text: String, entities: Entities) |
| 49 | +object Tweet { |
| 50 | + implicit val jCodec = SimpleJsonCodecBuilder[Tweet].build( |
| 51 | + "id_str", _.idStr, |
| 52 | + "text", _.text, |
| 53 | + "entities", _.entities |
| 54 | + ) |
| 55 | +} |
| 56 | + |
| 57 | +class RojomaAdaptor(name:String) extends LibraryAdaptor(name) { |
| 58 | + |
| 59 | + def initialize() {} |
| 60 | + |
| 61 | + def runOnce(json: String, doMap:Boolean) = { |
| 62 | + if (doMap) |
| 63 | + JsonUtil.parseJson[Tweet](json).get |
| 64 | + else |
| 65 | + JsonReader.fromString(json) |
| 66 | + } |
| 67 | + |
| 68 | + override def hasMap = true |
| 69 | + |
| 70 | +} |
0 commit comments