-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Feature/Support for QueryValue as a object #11787
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
base: 4.9.x
Are you sure you want to change the base?
Feature/Support for QueryValue as a object #11787
Conversation
@dstepanov can you think of a better way to do this? otherwise i think it's ok |
BeanIntrospection<T> introspection = introspectionOpt.get(); | ||
T instance; | ||
try { | ||
instance = introspection.instantiate(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why no-args constructor is required? I'think you need more tests with record
and required args constructor (without no-arg)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will update!
return BindingResult.unsatisfied(); | ||
} | ||
|
||
BeanIntrospection<T> introspection = introspectionOpt.get(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be altered to use introspection.builder()
so that records, immutable types, types with custom constructors etc. are supported.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When using IntrospectionBuilder
API and finally call the build()
method any exception should b caught and the conversion rejected with context.reject
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made the changes with the introspection.builder(). Seems to work for object with custom constructor but I made a test for record and don't work. Am I missing something?
…s, types with custom constructors etc.
http/src/main/java/io/micronaut/http/bind/binders/QueryValueArgumentBinder.java
Show resolved
Hide resolved
BeanIntrospection<T> introspection = introspectionOpt.get(); | ||
BeanIntrospection.Builder<T> introspectionBuilder = introspection.builder(); | ||
|
||
for (BeanProperty<T, Object> property : introspection.getBeanProperties()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
iterative here over the getBuilderArguments() using array iteration to obtain the index
http/src/main/java/io/micronaut/http/bind/binders/QueryValueArgumentBinder.java
Outdated
Show resolved
Hide resolved
http/src/main/java/io/micronaut/http/bind/binders/QueryValueArgumentBinder.java
Outdated
Show resolved
Hide resolved
Optional<Object> converted = conversionService.convert(value.get(), context.with(property.asArgument())); | ||
if (converted.isPresent()) { | ||
try { | ||
introspectionBuilder.with(propertyName, converted.get()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
invoke with passing the index from the array iteration https://docs.micronaut.io/latest/api/io/micronaut/core/beans/BeanIntrospection.Builder.html#with(int,io.micronaut.core.type.Argument,A)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried with getBuilderArguments() iteration, still not working for the records
No description provided.