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: Create custom deserializer to optionally URL encode query parameters #589

Conversation

WillBDaniels
Copy link

Fixes #577

This PR adds a custom deserializer to allow the sdk to properly deserialize urls of the form "http://test.test.com?param=this is a param" into a properly url-encoded URI object. this is currently only applied to the 'voice_url' field returned in the IncomingPhoneNumber, but can easily be added to other fields as needed. Maintains backwards and future compatibility with all response types, no breaking changes.

Checklist

  • I acknowledge that all my contributions will be made under the project's license
  • I have made a material change to the repo (functionality, testing, spelling, grammar)
  • I have read the Contribution Guidelines and my PR follows them
  • I have titled the PR appropriately
  • I have updated my branch with the main branch
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation about the functionality in the appropriate .md file
  • I have added inline documentation to the code I modified

…pplied to any url field of your choosing.
urlEncoded += "?" + splitEncodeAndReassembleQueryParams(queryParams);
}
encodedUrl =
new URL(urlEncoded).toURI();
Copy link
Contributor

Choose a reason for hiding this comment

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

I see some overlap between this and this. Recommend analyzing to determine what common logic can be extracted out.

import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't think all these new imports are needed.

@@ -379,6 +388,7 @@ private IncomingPhoneNumber(@JsonProperty("account_sid")
@JsonProperty("voice_method")
final HttpMethod voiceMethod,
@JsonProperty("voice_url")
@JsonDeserialize(using = com.twilio.converter.UriEncodingDeserializer.class)
Copy link
Contributor

Choose a reason for hiding this comment

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

This file (and the test file) are generated files (see header at top of files). If we're to make this change in the generator, it would affect all URI param types. I think this is fine, but just calling it out here,

@thinkingserious
Copy link
Contributor

Closing until PR feedback is addressed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants