Git Product home page Git Product logo

Comments (8)

MateuszKubuszok avatar MateuszKubuszok commented on September 27, 2024

Hey 👋, great thanks for suggestion!

I agree that such feature would be quite useful, but I would hesitate to enable it by default - virtually every feature that we ever added and had it turned on by default ended up with a bug report from someone who expected the code to fail/require manual intervention. I don't think that all such cases make sense (if one ends up with more configs than code they are helping to replace, it kind of misses the point), but this one feels like something that could be opt-in.

I recently started developing a feature allowing to customize how fields and subtypes are compared. It would address quite similar request for fields (#89) but also add an ability to customize comparison of subtypes/enum values.

If it was merged then adding enum support could be done e.g.

import io.scalaland.chimney.dsl.*
import io.scalaland.chimney.protobufs.*

implicit val config = TransformerConfiguration.default
  .enableCustomSubtypeNameComparison(PbEnumAwareNameComparison)

(alternatively, there could be several conventions prepared inside TransformedNamesComparison, one of them supporting UPPERCASE_WITH_UNDERSCORES).

Would such solution work for you?

I am not sure when I finish working on it. I started that mainly to take a break from some more mundane tickets that has to be implemented before 1.0.0-RC1, but I also have less time on mu hand AT.

from chimney.

saeltz avatar saeltz commented on September 27, 2024

Hey Mateusz, thanks for your reply!

I totally missed #89. #478 looks great. I think it would solve our problem. Do you think I could help somehow getting it merged?

from chimney.

MateuszKubuszok avatar MateuszKubuszok commented on September 27, 2024

I think right now, it's mostly grind:

  • replace all usages of "global" methods with something that uses ctx
  • write tests, they should make sure that top-level object/objects nested only on other objects work fine, and that disabling of the feature works as well
  • documentation - it should explain the limitation of this approach really well
    • to make code available to macro (we cannot rely on reify) it has to be available on the classpath
    • it also has to be instantiable with no dependencies
    • so the only sane choice are objects defined in module current module depends on
    • only then we can safely load object to memory and call it
    • it's basically unholy hack, but it seems to work

It isn't necessarily trivial, low-hanging fruit, but for the kind of work that happens in this project it's relatively simple - if you want to try, you can create a branch off #478 and see how it goes. :)

from chimney.

saeltz avatar saeltz commented on September 27, 2024

I continued in https://github.com/saeltz/chimney/tree/custom-name-comparator-saeltz.

All usages have been replaced with TransformerContext. Tests and documentation still missing.

from chimney.

MateuszKubuszok avatar MateuszKubuszok commented on September 27, 2024

Thank you! I've created a PR out of your changes.

from chimney.

MateuszKubuszok avatar MateuszKubuszok commented on September 27, 2024

Added in 1.0.0-M3

from chimney.

saeltz avatar saeltz commented on September 27, 2024

This is not really solved by #478. I opened #489.

from chimney.

MateuszKubuszok avatar MateuszKubuszok commented on September 27, 2024

I think it might be useful to have something OOTB in Chimney for some very common cases like Protobufs and Java integrations, however I need to point out that

This is not really solved by #478.

the whole point of #489 the PR is that everyone can add a custom comparator in their own codebase. The code in macros is as tricky as you see because we are not relying on pattern-matching on a sealed trait to obtain the comparator, but we are reading singleton value from the class-path by its type, so that every project is able to create and employ its own comparators without being blocked whether Chimney supports a particular convention OOTB.

from chimney.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.