Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use DerivedReads with 2 params? #73

Open
edrevo opened this issue Aug 11, 2020 · 1 comment
Open

How to use DerivedReads with 2 params? #73

edrevo opened this issue Aug 11, 2020 · 1 comment

Comments

@edrevo
Copy link

edrevo commented Aug 11, 2020

I am trying to migrate from 5.0.0 to 7.0.0, but I see that DerivedReads now has an extra TypeTag parameter. The README contains the following snippet, which I'm not sure works anymore with 7.0.0:

implicit val SecondReads: DerivedReads[Second] = new DerivedReads[Second] {
  def reads(tagReads: TypeTagReads, adapter: NameAdapter) = tagReads.reads("Second", (__ \ "foo").read[Integer].map(foo => Second(foo)))
}

since the compiler in my case is complaining that DerivedReads needs 2 params. Is there any ergonomic way of "ignoring" the second type param? My current code looks like this:

implicit def reads(implicit derivedReads: Lazy[DerivedReads[ApiEventV1]]): Reads[ApiEventV1] =
    derivedReads.value.reads(customTypeTagRead, NameAdapter.snakeCase)

And I would like to basically accept whatever in the second type param, but _ isn't working since the second type param is a generic type.

@julienrf
Copy link
Owner

Indeed, the documentation is outdated, we must update it.

Maybe the following works?

implicit def reads[X](implicit derivedReads: Lazy[DerivedReads[ApiEventV1, X]]): Reads[ApiEventV1] =
    derivedReads.value.reads(customTypeTagRead, NameAdapter.snakeCase)

However, maybe in your case you can use derived.withTypeTag? See API documentation here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants