-
-
Notifications
You must be signed in to change notification settings - Fork 98
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
Policy for checking which fields were used for transformation #248
Comments
Just to clarify, the thing implemented in test("Field.allMatching reports a compiletime failure when none of the fields match") {
final case class Source(int: Int, str: String, list: List[String])
final case class FieldSource(int: Long, str: CharSequence, list: Vector[String])
assertFailsToCompileWith {
"""
val source = Source(1, "str", List("list-str"))
val fieldSource = FieldSource(1L, "char-seq", Vector("vector-str"))
source.into[Source].transform(Field.allMatching(fieldSource))
"""
}("None of the fields from FieldSource match any of the fields from Source.")
} But it doesn't affect other parts of derivation, so you'd be the trailblazers here ❤️ |
We could 😉 But it would be seriously helpful to know more about use cases of this feature. I saw some options named "policy" in Java's MapStruct but I have no idea what users could find useful, so any feedback about this is welcome! For now we are mostly adding bugs and ideas to backlog to keep tabs on them, since we have a few things already planned (#239) and they will take some time 😄 |
There is a use case for policies in systems integrations with verbose and huge APIs (100-500 properties in single method/dto) when you want continuosly update their version in your application, such as legacy SOAP services. So, you can have compile time error for any unhandled changes with precise policy for the important parts and ignore unimportant ones. This is probably the main reason to use java's mapstruct in java or kotlin |
Hey @MateuszKubuszok thanks a lot for quickly reacting to my issue, and creating a vision for other enthusiasts to contribute. I volunteer to spend sometime to implement |
Some users would find it useful to be able to fail compilation if some/all fields from source were not used during derivation. Example of such thing was asked in this StackOverflow question: https://stackoverflow.com/questions/73927120/chimeny-scala-validate-source .
Such feature was implemented in ducktape so alternative libraries already decided that it is worth providing.
We could consider adding some/all of the setting:
.requireSourceFieldsUsed
.requireSourceFieldsUsed(_.fieldA, _.fieldB, _.fieldC)
.requireSourceFieldsUsedExcept(_.fieldA, _.fieldB)
.requireTargetSubtypesUsed
.requireTargetSubtypeUsed[SubType]
.requireTargetSubtypeNotUsed[SubType]
The text was updated successfully, but these errors were encountered: