Adding a generic ContainerSerializer[T]

已查看 19 次
跳至第一个未读帖子

j...@joescii.com

未读,
2017年8月7日 16:07:102017/8/7
收件人 Lift
While working on clustering concerns, I discovered that out of the box Lift only provides a handful of ContainerSerializer instances. When I went to change some of the Lift squeryl module's SessionVars to ContainerVars, I quickly discovered compilation failures such as the following: 

[error] /Users/joescii/Documents/code/oss/squeryl-auth-module/src/main/scala/net/liftmodules/squerylauth/AuthUser.scala:58: could not find implicit value for parameter containerSerializer: net.liftweb.http.ContainerSerializer[net.liftweb.common.Box[String]]
[error]   private object curUserId extends ContainerVar[Box[String]](Empty)
[error]              

There is only one instance of ContainerSerializer provided. It's the default java serialization, so it works for any object which itself and all references implement java.io.Serializable. But because Box[String] isn't one of the types in the companion object, we get the above compilation failure. 

I am about to open a PR which adds a ContainerSeriazlier[T <: Serializable]. This will be what the developer wants 99% of the time. In the event that this particular serializer fails, it's always possible to provide a different one.

I suppose this was originally designed the way it is because all of the provided serializers are guaranteed to work at run time. The one I'm proposing can never make such a guarantee, because an object can implement Serializable but hold a reference to something which doesn't. Hence in general, it's not possible to check for java.io serializability at compile time. 

Even though this loses compile-time guarantees, I think it's better than failing to compile when the needed code is already provided, just not typed appropriately. 

Any thoughts/concerns? 

Joe

Matt Farmer

未读,
2017年8月9日 13:41:442017/8/9
收件人 Lift
Why does T have to be a child of Serializable?

--
--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code

---
You received this message because you are subscribed to the Google Groups "Lift" group.
To unsubscribe from this group and stop receiving emails from it, send an email to liftweb+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Matt Farmer

未读,
2017年8月9日 13:42:072017/8/9
收件人 Lift
Oh wait, I misunderstood. hah. This sounds +1 to me. :D 
回复全部
回复作者
转发
0 个新帖子