Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added java.sql.Timestamp to net.liftweb.json Extraction #1308

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/json/src/main/scala/net/liftweb/json/Extraction.scala
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ object Extraction {
case JDouble(x) if (targetType == classOf[Number]) => x case JDouble(x) if (targetType == classOf[Number]) => x
case JString(s) if (targetType == classOf[String]) => s case JString(s) if (targetType == classOf[String]) => s
case JString(s) if (targetType == classOf[Symbol]) => Symbol(s) case JString(s) if (targetType == classOf[Symbol]) => Symbol(s)
case JString(s) if (targetType == classOf[Date]) => formats.dateFormat.parse(s).getOrElse(fail("Invalid date '" + s + "'")) case JString(s) if (classOf[Date].isAssignableFrom(targetType)) => formats.dateFormat.parse(s).getOrElse(fail("Invalid date '" + s + "'"))
case JBool(x) if (targetType == classOf[Boolean]) => x case JBool(x) if (targetType == classOf[Boolean]) => x
case JBool(x) if (targetType == classOf[JavaBoolean]) => new JavaBoolean(x) case JBool(x) if (targetType == classOf[JavaBoolean]) => new JavaBoolean(x)
case j: JValue if (targetType == classOf[JValue]) => j case j: JValue if (targetType == classOf[JValue]) => j
Expand Down
4 changes: 3 additions & 1 deletion core/json/src/main/scala/net/liftweb/json/Meta.scala
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package json


import java.lang.reflect.{Constructor => JConstructor, Field, Type, ParameterizedType, GenericArrayType} import java.lang.reflect.{Constructor => JConstructor, Field, Type, ParameterizedType, GenericArrayType}
import java.util.Date import java.util.Date
import java.sql.Timestamp


case class TypeInfo(clazz: Class[_], parameterizedType: Option[ParameterizedType]) case class TypeInfo(clazz: Class[_], parameterizedType: Option[ParameterizedType])


Expand Down Expand Up @@ -215,7 +216,7 @@ private[json] object Meta {
classOf[Short], classOf[java.lang.Integer], classOf[java.lang.Long], classOf[Short], classOf[java.lang.Integer], classOf[java.lang.Long],
classOf[java.lang.Double], classOf[java.lang.Float], classOf[java.lang.Double], classOf[java.lang.Float],
classOf[java.lang.Byte], classOf[java.lang.Boolean], classOf[Number], classOf[java.lang.Byte], classOf[java.lang.Boolean], classOf[Number],
classOf[java.lang.Short], classOf[Date], classOf[Symbol], classOf[JValue], classOf[java.lang.Short], classOf[Date], classOf[Timestamp], classOf[Symbol], classOf[JValue],
classOf[JObject], classOf[JArray]).map((_, ()))) classOf[JObject], classOf[JArray]).map((_, ())))


private val primaryConstructors = new Memo[Class[_], List[(String, Type)]] private val primaryConstructors = new Memo[Class[_], List[(String, Type)]]
Expand Down Expand Up @@ -392,6 +393,7 @@ private[json] object Meta {
case x: java.lang.Byte => JInt(BigInt(x.asInstanceOf[Byte])) case x: java.lang.Byte => JInt(BigInt(x.asInstanceOf[Byte]))
case x: java.lang.Boolean => JBool(x.asInstanceOf[Boolean]) case x: java.lang.Boolean => JBool(x.asInstanceOf[Boolean])
case x: java.lang.Short => JInt(BigInt(x.asInstanceOf[Short])) case x: java.lang.Short => JInt(BigInt(x.asInstanceOf[Short]))
case x: java.sql.Timestamp => JString(formats.dateFormat.format(x))
case x: Date => JString(formats.dateFormat.format(x)) case x: Date => JString(formats.dateFormat.format(x))
case x: Symbol => JString(x.name) case x: Symbol => JString(x.name)
case _ => sys.error("not a primitive " + a.asInstanceOf[AnyRef].getClass) case _ => sys.error("not a primitive " + a.asInstanceOf[AnyRef].getClass)
Expand Down