I am trying to wrap the play json writes macro expansion
def encoder[T] = Json.writes[T]
But the T
is unknown , so that won't compile, it complains
no unapply method found
I know I can replace Json.writes[T]
with JsMacroImpl.reads
expansion. Is there a better way doing this ?
I faced a similar problem some time back. you can do something like this.
create an object and inside write encoder method as a macro method.
object SomeObj {
def encoder[T] = macro encoderRedirect_impl[T]
def encoderRedirect_impl[T : c.WeekTypeTag](c:Context) = {
q"Json.writes[${c.weakTypeOf[T]}]"
}
}
This is a macro redirect for my understanding. but you have to write this code in seperate project and use it as a dependency to your project.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.