Can't you put the implicits in scope that will create the right kind of serializers that you need? Something to that effect:
def doNothingSerializer[T]: Serializable[T] = ???
implicit def mpostToJson(implicit pgs:Serializable[PrivateGroup]],
cmts:Serializable[List[MPostComment]]) =
new Serializable[MPost] {
def serialize(mpost: MPost): JObject = {
val privateGroupJSon = pgs.serialize(mpost.privateGroup)
// make the mpost json with privateGroupJSon which would be empty
???
}
}
// later where you need to serialize without the inner content:
implicit val privateGroupToJson = doNothingSerializer[PrivateGroup]
implicit val mpostCommentsToJson = doNothingSerializer[List[MPostComment]]
implicitly[Serializable[MPost]].serialize(mpost)
You would need to define default serializable instances in a trait that is then inherited (so that low priority implicits are in scope).
Note that I'm assuming that the trait for Serializable is:
trait Serializable[T] {
def serialize(t: T): JObject
}
(no [T]
method type argument and returns a JObject
)