-
Notifications
You must be signed in to change notification settings - Fork 445
feat: Support custom ObjectMappers, with singleton defaults #844
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
feat: Support custom ObjectMappers, with singleton defaults #844
Conversation
Hello! |
Hi! Sure - I'd like to be able to provide my own object mapper (a singleton instance, with some customization applied) while constructing a RestClient. Right now, it's not possible to provide my own, and additionally, a new object mapper gets created for each client. Ideally, I want to be able to do something like: private static final ObjectMapper MY_CUSTOM_MAPPER = //...
//...
TwilioRestClient client = new TwilioRestClient
.Builder(username, token)
.objectMapper(MY_CUSTOM_MAPPER)
//...
.build() Even without support for custom object mappers, having a single static default ObjectMapper would be a nice improvement. I currently use the SDK to make 10s-100s of requests per second across thousands of subaccounts, and the fact that I'm constructing a new ObjectMapper (an expensive operation) every time I create new a rest client (with auth for a different subaccount) isn't ideal. |
Thanks for the example. I understood what is your use case. |
49cbac8
to
0ee9dc2
Compare
Hey @manisha1997 - I've updated the test, and it should be passing now! |
@egoodhall, I tested these changes. This will still create multiple mappers for each TwilioRestClient, so, the heap memory problem will still exist. |
Hey @manisha1997 - I'm not sure I follow. By default, it will use the It doesn't (and can't) verify that provided custom object mappers are the same instance, but I think if an override is provided for the object mapper, it's outside of the SDK's responsibilities to worry about that. |
Ohk. I was under the assumption that even the custom mappers will only be 1 throughout the Application. |
Fixes
Adds support for providing a custom ObjectMapper to the rest client builders. If no ObjectMapper is provided to the builder, a default one which matches the existing configuration will be used. The default ObjectMapper for each rest client type will also now be held in a static variable, so we aren't instantiating a new one every time a rest client is created.
Checklist
If you have questions, please file a support ticket, or create a GitHub Issue in this repository.