-
Notifications
You must be signed in to change notification settings - Fork 966
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
added option to switch off validation for ConfigBeanFactory use #602
Conversation
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.
Thanks!
I would recommend adding tests for some of the main cases to check that they throw in validation mode and don't throw in non-validation mode. Otherwise this will break the first time someone touches this file again, it's an annoyingly hard file to modify reliably.
@@ -4,7 +4,7 @@ | |||
// Release tags should follow: http://semver.org/ | |||
import scalariform.formatter.preferences._ | |||
|
|||
ThisBuild / git.baseVersion := "1.3.0" | |||
ThisBuild / git.baseVersion := "1.3.4" |
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 is an unrelated change I guess, ideally not in this PR
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.
the current release is 1.3.3, so I don't know why this was set to 1.3.0.
I changed it to 1.3.4, so that my local publication is at a higher version than the release.
(perhaps it should still read 1.3.3 or 1.3.0?)
* | ||
* @param config source of config information | ||
* @param clazz class to be instantiated | ||
* @param validate passing false means that the config will not be validated against the bean's implied schema |
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 don't love the boolean param ( long story https://blog.ometer.com/2011/01/20/boolean-parameters-are-wrong/ , tldr create(config, clazz, false)
doesn't read well).
An alternative would be an Options object like ConfigParseOptions / ConfigResolveOptions, or an enum like ValidationMode { NONE, AUTOMATIC }
or something.
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.
That would be an acceptable alternative. though I am fine with booleans.
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 am also looking forward to this feature, since i also need it. Therefore, thanks for your contribution on it :)
But i would also think it would be nicer to have more control on the validation. For example to keep the "type" validation for non-null fields, but ignore the optional/null value check, thus allowing null values but validating the type on non-null ones. And similar.
Currently the boolean is disabling/enabling everything
* Fields are mapped to config by converting the config key to | ||
* camel case. So the key <code>foo-bar</code> becomes JavaBean | ||
* setter <code>setFooBar</code>. | ||
* |
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 think this kinda needs to explain what happens if we disable validation and it's invalid. I believe the answer is stuff gets left as whatever it was set to originally in the bean (stuff does not get assigned). But full-on type errors (assign an integer to a list or something) maybe still throw?
val e = intercept[ConfigException.Parse] { | ||
ConfigFactory.parseReader(configInput) | ||
} | ||
assertThat(e.getMessage, containsString("Expecting end of input or a comma, got '^'")) | ||
} |
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.
are there changes in this file or just accidental reformatting?
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 changed nothing here.
Feel free to add to this pull request or superceed it. I have done all i am
able to do at this time.
…On Wed 19. Dec 2018 at 09:32, Ignacio Rodriguez ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In config/src/main/java/com/typesafe/config/ConfigBeanFactory.java
<#602 (comment)>:
> + *
+ * The Java class should follow JavaBean conventions. Field types
+ * can be any of the types you can normally get from a ***@***.***
+ * Config}, including <code>java.time.Duration</code> or ***@***.***
+ * ConfigMemorySize}. Fields may also be another JavaBean-style
+ * class.
+ *
+ * Fields are mapped to config by converting the config key to
+ * camel case. So the key <code>foo-bar</code> becomes JavaBean
+ * setter <code>setFooBar</code>.
+ *
+ * @SInCE 1.3.4
+ *
+ * @param config source of config information
+ * @param clazz class to be instantiated
+ * @param validate passing false means that the config will not be validated against the bean's implied schema
I am also looking forward to this feature, since i also need it.
But i would also think it would be nicer to have more control on the
validation. For example to keep the "type" validation for non-null fields,
but ignore the optional/null value check, thus allowing null values but
validating the type on non-null ones. And similar.
Currently the boolean is disabling/enabling everything
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#602 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AFW7Zc_PhE8dwvBsDnmxBbuYHiFAb56Mks5u6fmagaJpZM4Y-eNk>
.
|
Just added a PR to your own fork with some small changes to match the mechanism of other parts of the library and enable future settings if needed, plus a mini test Thanks :)
|
Introduce a bean factory options parameter
Hello there !! @havocp @dhakehurst |
I do not currently have more time to work on this
…On Fri, 15 Feb 2019 at 06:21, Arnaud Villevieille ***@***.***> wrote:
Hello there !! @havocp <https://github.com/havocp> @dhakehurst
<https://github.com/dhakehurst>
Do we have new about that change?
Does someone plan to have it merged into the project?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#602 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AFW7ZZ1fPRsB-tlEFZD9mkC44F4SgNX_ks5vNkPEgaJpZM4Y-eNk>
.
|
I will continue this change on a new PR instead then. -> #616
|
Closing this since it moved to #616 |
Useful in its own right I believe, but this also provides a work around for #440
I have beans that I want instantiated by the config file. But I don't want to set every property of the bean. The bean itself sets default values for some properties. I cannot add the '@optional' annotation to the bean class properties.
switching off the validation allows this.
(I'm using this library for a live project, it is very useful, thanks for all who have contributed towards it.
I need this capability ASAP, and I would rather use an official release over my patched version.)
I have signed the Typesafe Contributor License Agreement online