简体   繁体   中英

circe automatic derivation - struggling with the imports

I have a method exposed on my API that looks like this:

def read[T](implicit decoder: Decoder[T]): T

A user can bring along any T they like and my code will attempt to parse the json result into a T .

The issue I want to resolve is that any user must also import io.circe.generic.auto._ in order to get this to work and auto-derive the Decoder[T] .

Is there any way I can change my API to avoid the user having to bring this import?

It could be if you do it in a library - implicits would easily conflict causing troubles for your users.

In Typelevel Scala 4 can use customizable imports - it didn't landed in Scala 2.12 but (after several iterations) landed on 2.13 . You could recommend your users have some implicits always in scope this way once 2.13.0 is released, but that will be conscious decision on their part.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM