-
Notifications
You must be signed in to change notification settings - Fork 116
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
expose conversion mechanism in API #492
Comments
In SmallRye Config, we expose that functionality like this: public <T> T convert(String value, Class<T> asType) {
return value != null ? getConverter(asType).convert(value) : null;
}
public <T> Converter<T> getConverter(Class<T> asType) {
// ...
} Which can be useful if one wants to cache the converter or perform repeated conversions, or create delegating converters, etc. We also (internally) support |
I know converter is a useful functionality. I talked with someone else to potentially create a converter spec. Since it is a smallish update, I'll attempt to propose a PR soon. |
Actually, I thought about this more yesterday and I'm not sure about adding the convert on the config api. It should not belong to Config object, which just a collections of configuration. My proposal is to is directly expose Converter. I think we can do:
A PR will follow soon. |
This statement is incorrect. The |
I agree with @dmlloyd. Personally, I’d like to see clearer separation between API and SPI so I think we should not leak |
|
+1 to the PR as it stands.
Exposing I don't think you'd want to use a converter within |
Configuration converters are primarily used in the context of config. If you're trying to get to having a general purpose conversion framework, that is something else altogether, and would probably have different requirements and uses (and doesn't belong in the MP Config specification at any rate - perhaps it would be worth a new MP specification for that purpose, if the scope & use cases could be identified). |
I would argue that the specified use of converters in microprofile-config is always in the context of a config. Multiple converters can exist for a given type and the selection of which converter to use depends on the converters known to a config and their respective priorities. Having access to the specific converter selected by the config for a given type could certainly be useful, so I like the SmallRye approach. |
to expose converters along with the ability to directly convert, I propose the following additions to default <T> T convert(String value, Class<T> type) {
return value == null ? null
: getConverter(type).orElseThrow(() -> new IllegalArgumentException("no converter available for " + type))
.convert(value);
}
<T> Optional<Converter<T>> getConverter(Class<T> forType); Essentially the same thing as SmallRye but with an exception-free way to indicate the absence of a suitable converter. |
It looks reasonable to me - although I don't like that our implementation will become incompatible; maybe a method name change would be possible? |
Yeah, I noticed the name collision with SmallRye, also. I took at a stab and reworking the SmallRye implementation and it doesn't seem too onerous to rename the existing SmallRye method, but of course that would be a breaking change to anyone using the SmallRyeConfig API directly. I'm not necessarily opposed to a different name, but |
We can talk about this in the next release. I think separate Convert with Config property is better, so that coverter can be easily used by other spec for strict convesion usage. |
Holding this change for some future global conversion spec is not a wise course. If such a specification does ever materialize, only then should we consider applying it to this specification. In the meantime, we should assume that no such specification exists and proceed on that basis. Blocking useful features because a new specification might appear is not responsible stewardship IMO. So, I disagree: let's address this for 1.5 or 2.0 if we can't get it in to 1.4. |
I have the following reasons that this issue is not in the scope of 1.4.
|
My primary motivation for this issue is to provide a way for a user to programmatically convert a default value known to the application in the same way the injection facility does. I find it very strange that this and #496 are meeting such resistance. I am essentially just looking for feature parity between Whether or not this can wait for the next release depends a lot on when that release is expected to happen. It's been 20 months since 1.3, and I had no idea the release train for 1.4 was departing until RC1 and RC2 arrived back to back. How do I learn more about the schedule for releases? I can appreciate the pressures and challenges of running the project, but as a user and proponent of MicroProfile I'm trying to balance my desire to remain compliant with the standard for portability against the convenience offered by alternatives. I know I'm not alone with this challenge so i want to help push things along if I can. |
I agree that at this time it is hard to include additional features to 1.4. Considering the amount of discussion and back and forward with the null issue, I see that this particular one going on the same path and unfortunately there is no time for it if we want to get something out. I also agree that we need to have a more clear roadmap, so contributors are aware of the release plan so they are able to push and advocate for the features they need to be included in the release cycle. |
@emattheis If you check the due date on milestone, you will find out the target date. The release train is departing. As for last year, we spent a lot of time discussing dynamic aspect of Config and created APIs. However, this is a great fit for Quarkus, which is static. We then undid a lot of stuff. We now take everyone onboard and align with each other. As @radcortez said, we will get the Config 1.4 out and then discuss what we want to focus on 2.0 so that we won't run into the same issue as last year. I understand your frustration. Hope we can move along faster after 1.4 release! |
Got it. We should get his linked up on the readme or contribution docs so it's clear. Onward to 2.0! |
This should be included in 2.0 at least. There's simply no reason not to. |
MP-JWT requiring a Converter spec: microprofile/microprofile-jwt-auth#100 |
How should we proceed with this for 2.0? Should we just expose some of the Converter method in Config? |
I asked @emattheis to rebase #495; once he does, @Emily-Jiang, could you please review it again from the perspective of possible inclusion in 2.0? @radcortez you could review too if you wish. |
I rebased the PR. Also wondering if we should drop the |
This issue can now be closed, since #495 was merged. |
There are certain cases where a user of microprofile-config might want to convert a supplied string into different type using the same mechanism as a resolved property value. For example, when a fallback value for a particular usage point is available from a string supplier, but not appropriate to contribute as a formal config source.
I suggest adding the following method to
org.eclipse.microprofile.config.Config
:The text was updated successfully, but these errors were encountered: