Seems we now only support apply whose signature is same as default constructor, which is good. However, the unexpected thing is that if there are multiple apply, the pickling still doesn't work.
SInce there is only one apply with same signature as primary constructor, is it possible to select that apply when deserializing?
class GGraph[N, E](val vertexList: List[N], val edgeList: List[(N, E, N)])
object GGraph {
def apply[N , E](vertexList: List[N], edgeList: List[(N, E, N)]): GGraph[N, E] = {
new GGraph[N, E](vertexList, edgeList)
}
def unapply[N, E](graph: GGraph[N, E]): Option[(List[N], List[(N, E, N)])] = {
Some((graph.vertexList, graph.edgeList))
}
def apply[N, E](other: GGraph[N, E]): GGraph[N, E] = {
new GGraph[N, E](other.vertexList, other.edgeList)
}
}
//test
//==============
"Graph" should "be able to serialize/deserialize correctly" in {
val graph = new GGraph[Int, String](List(0, 1), List((0, "edge", 1)))
val serialized = write(graph)
val deserialized = read[GGraph[Int, String]](serialized)
graph.vertexList.toSet shouldBe deserialized.vertexList.toSet
graph.edgeList.toSet shouldBe deserialized.edgeList.toSet
}
exception:
Error:(43, 49) type mismatch;
found : [N, E](other: org.apache.gearpump.util.GGraph[N,E])org.apache.gearpump.util.GGraph[N,E] <and> [N, E](vertexList: List[N], edgeList: List[(N, E, N)])org.apache.gearpump.util.GGraph[N,E]
required: (List[Int], List[(Int, String, Int)]) => org.apache.gearpump.util.GGraph[Int,String]
val deserialized = read[GGraph[Int, String]](serialized)
^
in PR https://github.com/lihaoyi/upickle-pprint/commit/b8d897e8f589e2144d668d4b3978b371232eb591
Seems we now only support apply whose signature is same as default constructor, which is good. However, the unexpected thing is that if there are multiple apply, the pickling still doesn't work.
SInce there is only one apply with same signature as primary constructor, is it possible to select that apply when deserializing?
exception:
ID: 102 Original Author: clockfly