Skip to content

Instantly share code, notes, and snippets.

@rktoomey
Created June 28, 2012 17:56
Show Gist options
  • Save rktoomey/3012871 to your computer and use it in GitHub Desktop.
Save rktoomey/3012871 to your computer and use it in GitHub Desktop.
For Marcus
scala> import model._
import model._
scala> val afghanistan = JSONCountry("9c5bae60-4d6f-e111-afed-00155d6f0a00", "Afghanistan")
afghanistan: model.JSONCountry = JSONCountry(9c5bae60-4d6f-e111-afed-00155d6f0a00,Afghanistan)
scala> val j = JSONData(afghanistan :: Nil)
j: model.JSONData = JSONData(List(JSONCountry(9c5bae60-4d6f-e111-afed-00155d6f0a00,Afghanistan)))
scala> j.toJSON
res0: net.liftweb.json.package.JObject = JObject(List(JField(countries,JArray(List(JObject(List(JField(countryID,JString(9c5bae60-4d6f-e111-afed-00155d6f0a00)), JField(country,JString(Afghanistan)))))))))
package myApp
import com.novus.salat.{TypeHintFrequency, StringTypeHintStrategy, Context}
import com.novus.salat.json._
import org.joda.time.format.ISODateTimeFormat
import org.joda.time.DateTimeZone
import com.novus.salat.StringTypeHintStrategy
package object context {
implicit val ctx = new Context {
val name = "json-test-context"
override val typeHintStrategy = StringTypeHintStrategy(when = TypeHintFrequency.WhenNecessary,
typeHint = "_t")
override val jsonConfig = JSONConfig(
dateStrategy = StringDateStrategy(dateFormatter = ISODateTimeFormat.dateTime.withZone(DateTimeZone.forID("US/Eastern"))),
objectIdStrategy = StringObjectIdStrategy)
}
}
package model
import myApp.context._
import com.novus.salat._
case class JSONData(
countries: List[JSONCountry]) {
def toJSON = grater[JSONData].toJSON(this)
}
case class JSONCountry(
countryID: String,
country: String)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment