Closed AhmedLSayed9 closed 1 month ago
Mappers are always registered globally. There cannot be two different mappers for the same type.
But I can make the docs more clear on this.
Mappers are always registered globally. There cannot be two different mappers for the same type.
I meant when adding includeCustomMappers
to some class annotation, it should only work for instances of that class type.
I understand. It would be a super huge change in how the package works and quite some work, which I don't have time for currently. So it won't be done anytime soon.
Thank you for the wonderful package. The convenient API and functionality are impressive; it's excellent. 🤩
I had never used includeCustomMappers
, but I decided to migrate a working project to this package and noticed from some tests that date serialization here is in UTC by default. I decided to change it globally, but unfortunately, you have to call a method to override DateTimeMapper.encodingMode
, and this needs to be called in the code both before the tests and when starting the program. It's easy to forget, and it's impossible to set it by default at the code generation level 😔.
I decided to override it at the level of certain models using includeCustomMappers, and I realized that it works well in tests, but in production, it affects other classes where includeCustomMappers was not used.
It's very unexpected behavior.
I updated the docs to be more clear.
Unfortunately there is nothing else I can do about this.
Similar to #195, I got confused about using
includeCustomMappers
property atMappableClass
and it was very hard to catch its global state behavior.I don't get this idea of adding
includeCustomMappers
toMappableClass
annotation while it'll change the global state for all other classed after that annotated class is called anyway.That weird behavior caused a bug on my end that was very hard to catch. Specifically that includeCustomMappers api doc says:
Specify additional custom mappers that should be included for fields of this class.
. "this class" is meant to refer solely to its own class and should not be globalized to all other classes.I suggest to either update it to just work for the class it's annotated with, or remove it from the class annotation and users can use
MapperContainer.globals.use(CustomMapper())
instead.