jooby-project / jooby

The modular web framework for Java and Kotlin
https://jooby.io
Apache License 2.0
1.71k stars 196 forks source link

RelfectiveBeanConverter issue - not decoding HashValue with contructor injection #1531

Closed Burtsev-Alexey closed 4 years ago

Burtsev-Alexey commented 4 years ago

joobyInject

Context ctx;
LoginModel model = ctx.form(LoginModel.class);

@Inject
public LoginModel(String username, String password) {
    this.username = username;
    this.password = password;
}

This code doesn't work as expected. fields always remain null.

The reason for this is demonstrated in attached image. It turned out that java doesn't preserver method arguments name, so injecting by name doesn't work.

jknack commented 4 years ago

are you on maven? make sure the compiler plugin setup correctly. Same if you compile with IDE (IDE must be configured with parameter names).

Burtsev-Alexey commented 4 years ago

Yes, I'm using Maven for building. Looks like I need to add '-g:vars' compile option. It would be good to mention this in documentation, or even better do:

          if(!parameter.isNamePresent()) {
                throw new IllegalArgumentException("Parameter names are not present!");
            }
jknack commented 4 years ago

yes, you are right. going to add it.