-
Notifications
You must be signed in to change notification settings - Fork 41.1k
It is recommended that when the parsing value is null, it can be customized by BindHandler #17050
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
Comments
Thanks for the suggestions. Unfortunately, I don't think we can proceed with them as they are both breaking changes:
Rather than describing possible solutions, can you please take a step back and describe the problem that you are facing? |
I need to dynamically bind attributes to beans, so I use binder API, but some attributes are not standard field mapping, so I want to use a custom handler to process Look at my demo please. I hope that the |
Do you understand my question? look forward to your reply @wilkinsona @spring-issuemaster |
I would not recommend trying to reuse the It seems like you're trying to support a form of fallback properties. The user can set public static String getSlaveJdbcUrl(MyBatisProperties properties) {
String result = properties.getSlaveJdbcUrl();
if (result == null) {
result = properties.getSlave().getSlaveJdbcUrl();
}
return result;
} |
We're not keen to add additional complexity to the Binder to support fallback functionality. See #7986 for background. |
@philwebb Sorry, I don't think this is a good solution to my problem, because I may have to write a lot of such logic code, I want to call Binder API binding dynamically, so |
You mean the Perhaps you can subclass the protected final <T> T bind(ConfigurationPropertyName name, Bindable<T> target,
BindHandler handler, Context context, boolean allowRecursiveBinding) { |
@philwebb Thank you for your reply, but the final method cannot be rewritten. I've implemented my requirements through two solutions. |
I'm sorry, but we don't want to expand the surface area of the public API. Your specific use-case is quite unusual and as such I think that maintaining your own copy of the code is the best approach. |
@philwebb Thank you for your reply |
org.springframework.boot.context.properties.bind.Binder

It is recommended that when the parsing value is null, it can be customized by BindHandler,because when the return value is null, I need to give a default value through BindHandler,the recommended code is modified as follows:

The second solution is that the finish method of bindhander can add method return value,the code is as follows:

The text was updated successfully, but these errors were encountered: