Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Nice ParaNameReader for the Play! Framework v.1.2.2
package PlayParameterReader
/**
* @author Jay Taylor <outtatime@gmail.com>
*
* @date 2011-05-23
*/
import scala.collection.JavaConversions._
import java.lang.reflect.Constructor
import java.sql.Timestamp
import java.text.SimpleDateFormat
import play.classloading.enhancers.LocalvariablesNamesEnhancer
import net.liftweb.json._
import net.liftweb.json.JsonAST
import net.liftweb.json.JsonDSL._
object PlayParameterNameReader extends ParameterNameReader {
def lookupParameterNames(constructor: Constructor[_]) =
LocalvariablesNamesEnhancer.lookupParameterNames(constructor)
}
class TimestampSerializer extends Serializer[Timestamp] {
private val TimestampClass = classOf[Timestamp]
def deserialize(implicit format: Formats):
PartialFunction[(TypeInfo, JValue), Timestamp] = {
case (TypeInfo(TimestampClass, _), json) => json match {
case JString(s) => new Timestamp((new SimpleDateFormat).parse(s).getTime)
case x => throw new MappingException("Can't convert " + x + " to Timestamp")
}
}
def serialize(implicit format: Formats): PartialFunction[Any, JValue] = {
case x: Timestamp => JString((new SimpleDateFormat).format(x))
}
}
object Formats {
implicit val formats = new DefaultFormats {
override val parameterNameReader = PlayParameterNameReader
} + (new TimestampSerializer)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.