Skip to content
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

fix: support binding Body form-url-encoded to POJO with lambda Apps #1414

Merged
merged 22 commits into from
Jul 28, 2022

Conversation

sdelamo
Copy link
Contributor

@sdelamo sdelamo commented Jul 22, 2022

No description provided.

@@ -0,0 +1,406 @@
/*
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is forked from Netty as we do in core

return Optional.empty();
}
if (nestedBody(bodyArgument)) {
return Optional.of(formUrlEncodedBodyToConvertibleValues(body));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If @Body("name"), we are transforming the body into a map and then creating a ConvertibleValues

if (nestedBody(bodyArgument)) {
return Optional.of(formUrlEncodedBodyToConvertibleValues(body));
}
return bindFormUrlEncoded(bodyArgument, body);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if Body is not nested), we are transforming the body into a map and then using BeanPropertyBinder to bind map to POJO.

@sdelamo
Copy link
Contributor Author

sdelamo commented Jul 25, 2022

Sonatype complains mostly about forked from Netty QueryEncoder

@sdelamo sdelamo added the type: bug Something isn't working label Jul 25, 2022
@sdelamo sdelamo changed the title fix: support form-url-encoded with lambda Apps fix: support binding Body form-url-encoded to POJO with lambda Apps Jul 25, 2022
@sdelamo sdelamo marked this pull request as ready for review July 25, 2022 08:07
@sdelamo sdelamo requested a review from timyates July 25, 2022 09:38
@timyates
Copy link
Member

Do we need to support multipart (ie a File upload) as well. Do we need a new issue for that?

@sdelamo
Copy link
Contributor Author

sdelamo commented Jul 25, 2022

Do we need to support multipart (ie a File upload) as well. Do we need a new issue for that?

There are probably issues with multipart but I think we should target that in a different PR.

@timyates
Copy link
Member

I pushed a test, and some fixes for Sonar

@timyates
Copy link
Member

timyates commented Jul 25, 2022

@sdelamo This fixes the "unannotated body" for a form encoded Body, by converting the Map to a JsonNode and going through the existing converter path

74fa5c6

@timyates
Copy link
Member

@sdelamo So, the fix for map responses was to convert the GroovyString to a String in the controller 779757d

We don't need to do this in netty controllers, so I'm not sure what we're missing 🤔

try {
return Optional.of(beanPropertyBinder.bind(argument.getType(), source));
} catch (ConversionErrorException e) {
return Optional.empty();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Swallowing this might be undesirable, what if the error needs to be returned to the user or the developer is trying to understand why binding failed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added a log statement 515e34a

@sonarcloud
Copy link

sonarcloud bot commented Jul 26, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

83.4% 83.4% Coverage
0.0% 0.0% Duplication

@sdelamo
Copy link
Contributor Author

sdelamo commented Jul 27, 2022

@graemerocher any concern with merging this?

@sdelamo sdelamo merged commit e962132 into 3.5.x Jul 28, 2022
@sdelamo sdelamo deleted the issue-1410-pojo-binding branch July 28, 2022 09:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Binding form url encoded to POJO fails
4 participants