Scala Pickling and type parameters

前端 未结 2 1509
遇见更好的自我
遇见更好的自我 2021-02-06 09:20

I\'m using Scala Pickling, an automatic serialization framework for Scala. According to the author\'s slides, any type T can be pickled as long as there is an impli

2条回答
  •  鱼传尺愫
    2021-02-06 09:51

    Looking at the project, it seems you need either an scala.pickling.SPickler or a scala.pickling.DPickler (static and dynamic, respectively) in order to pickle a particular type.

    The pickle methods are macros. I suspect that if you pickle with an SPickler, the macro will require the compile time type of your class to be known.

    Thus, you may need to do something similar to:

    object Foo {
      def bar(t: SomeClass1) = t.pickle
      def bar(t: SomeClass2) = t.pickle
      def bar(t: SomeClass3) = t.pickle
      // etc
    }
    

    Alternatively, a DPickler may do the trick. I suspect that you'll still have to write some custom pickling logic for your specific types.

提交回复
热议问题