question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Remove auto-derivation enabled by default

See original GitHub issue

Hi there,

This might be a bit controversial, but auto-derivation is bringing quite a few non-small problems to us, from increased compilation times, to inadvertently, codifying case class that weren’t expected to be there.

We are defining the Codecs/SchemaFor explicitly, and that helps, but it’s inconvenient to not have the help of the compiler to tell you which one is missing because the missing ones are auto generated.

I would rather have explicit imports for the required behaviour, like circe or zio-json:

  • import com.sksamuel.avro4s.derivation.auto._
  • import com.sksamuel.avro4s.derivation.semi._

I am aware if accepted this is a breaking change, but If accepted, I would be willing to put forward a PR.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:9
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jeffmaycommented, Oct 7, 2021

Yea, this one bit me too. I spent days trying to figure out why the FieldMapper wasn’t working. It turns out that the macro looks at the local scope at every point where the Decoder is requested. This means that you cannot define the correct FieldMapper for the model in the companion object where the schema is generated (as you do for most type-class based codecs). This is especially a problem when some models use snake_case and others do not as you cannot mix the two in a generic situation as you cannot know which type needs which FieldMapper. The fact that auto-derivation is the default and the field mapper is assumed based on local scope effectively makes the FieldMapper unusable for us.

0reactions
atnoyacommented, Jun 8, 2021

Yeah, pretty much, I would say:

Semiauto is where you define your typeclass instances in the companion object (usually) by calling the gen macro.

And at the calling site, e.g.:

def useMyEncoder[A: Encoder]: Unit = ???

//If encoder defined in the companion object use that. 
//If you wish to use auto derivation, just include:
//import com.sksamuel.avro4s.derivation.auto._
useMyEncoder[A]

//If you don't define an instance in the companion object of A (or include a relevant import where the Encoder is defined), or add the `auto` import, compilation will not be able to find a suitable instance, and hence, failing.
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to turn off form autocompletion - Web security | MDN
This article explains how a website can disable autocomplete for form fields. By default, browsers remember information that the user ...
Read more >
Macros from the internet will be blocked by default in Office
Provides guidance for admins about how Office blocks macros in files from the internet.
Read more >
Auto DevOps - GitLab Docs
GitLab triggers the Auto DevOps pipeline on the default branch. To disable it, follow the same process and clear the Default to Auto...
Read more >
Delete significant locations on iPhone
In Maps on iPhone, delete records of the places you recently visited.
Read more >
Reset/remove CSS styles for element only
For example certain elements like textarea by default have a border, ... You are simply building on a reset common core set of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found