Spring's argument resolver mechanism is very flexible and fits most of the scenarios. However, since nowdays most of applications uses Lombok and immutable objects with builders, t would be very good to have option to bind request argument directly to builder instance instead (I mean in addition to) Java Bean compliance objects only.

In my head it is kind of similar and straight forward - instead of introspecting setter/getter method to match request name, resolver would have to introspect methods to resolve those.

Comment From: rstoyanchev

I think you're talking about data binding for @ModelAttribute arguments but you're mentioning "Spring's argument resolver mechanism" which is something broader. It is what supports many other kinds of arguments of which @ModelAttribute is just one example. Can you clarify what you mean?

Comment From: Antoniossss

It is easier for me to explain by example as I am not fluent in common nomenclature.

Leets have for example following DTO

@Data // creates getters/setters
public class MyDto{
  .... set of private Fields
}

And I use it like this

@PostMapping(...)
public void myWebMethod(MyDto dto){
      // 
}

Here post params (or query, does not matter) will be bound gracefully to MyDto due to fact that it has getters/setters which names matches params in the request. Now, It would be nice If I would be able to use exact the same mechanism but with Immutable DTO object.

@Builder
@Getter
public class MyDto{
  .... set of *prvate final* Fields
}

Now I would like to use such DTO in the same manner I could use it when it was in JavaBean form.

In JavaBean example, matching (as far as I am aware) is done by setter name - argument name matching. Here, it could be done using builder methods.

UNLESS - it is already working like that because I didnt try to do this using builder class as argument.

Comment From: rstoyanchev

Okay it's more clear now. No there is no support for this right now. You can however bind via constructors.

Comment From: Antoniossss

will it match arguments by constructor arg names? this would actually work in similar way to what i neededed in the first place(autobind to immutable dto)

pon., 27.01.2020, 15:27 użytkownik Rossen Stoyanchev notifications@github.com napisał:

Okay it's more clear now. No there is no support for this right now. You can however bind via constructors.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/spring-projects/spring-framework/issues/24411?email_source=notifications&email_token=AB4DH64IVW3QZGZTGKUVXATQ73VMJA5CNFSM4KKBHC42YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEJ7V7NA#issuecomment-578772916, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB4DH6YLTDK26V2IBNTFRDDQ73VMJANCNFSM4KKBHC4Q .

Comment From: rstoyanchev

Yes it discovers constructor parameter names, much like it does for say @RequestParam method arguments, e.g. via reflection in Java 8+ if compiled with --parameters or from local variable table otherwise if compiled with debug info. It supports @ContructorProperties as well. See Javadoc.

Comment From: Antoniossss

allright then. This sums up my requirement and futher additions are not needed. Thank you very much