-
-
Notifications
You must be signed in to change notification settings - Fork 152
Need a way to escape dots in property keys (add path separator configuration) #169
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
Please make sure to first read README of https://github.com/FasterXML/jackson-dataformats-text/tree/master/properties (link to from main README of and specifically part about using |
Aye, but I don't want to change the separator, because that will confuse anyone setting these properties (as they will expect them to use dots, 'cos that's what everyone does). I can't see any way to do that with the JavaPropsSchema as it is. |
Right, there is no escape mechanism currently, as escaping from external input is handled by default JDK The big problem here however is this: parsing/decoding is currently delegated to JDK I do not have time to work on this myself but it seems like a reasonable idea. |
Things may have changed a lot in the last nearly three years, but looking at the props mapper now I think the issue can be resolved in the various Splitter implementations (JPropPathSplitter and its children). |
Ah, this is the fundamental thing I was missing:
(from https://docs.oracle.com/en/java/javase/15/docs/api/java.base/java/util/Properties.html) I'm not sure we need to worry too much about that - the user simply has to use twice as many backslashes.
|
PRs welcome (against 2.14), sounds like a useful improvement. |
There seem to be a few areas to consider in working on an improvement and I'd like your opinion on them:
Given that this only affects the properties mapper I may be worrying too much about performance. |
PR #332 as a working, minimal, attempt. |
@Yaytay great questions! Let me see.
On PR, yes, will try to have a look soon -- thank you for contributing it! |
There are (at least) two problems in the first version of the PR:
More tests needed. |
Updated the PR. |
Hmmh. Is the idea of default being NULL character that it would be same as having none? If so I can see it as "not defined" -- which is fine; I consider that invalid within properties file -- but wanted to double check. |
Yes, that's precisely the intention - I think it should not be possible for my changes to affect any existing prop files being processed without developer intervention. I could make it a Character instead, but then I'd either have to check for null or cast to an int in CharPathOnlySplitter.splitAndAdd on each return from indexOf. i.e. change JavaPropsSchema to make pathSeparatorEscapeChar a Character, then in CharPathOnlySplitter store an int that is either the char value or -1 if it's null, and cast the result from charAt to an int before comparing with the escape char:
|
Hi again, Now that 2.14.0-rc1 is out I've just found that there is no way for me to actually use this :( Not sure what the best solution is, but can we either add an override or change the access on something so that JavaPropsMapper can create a Reader with both a custom schema and a valueToUpdate? Jim |
This is my hacky subclass which does work, so I'm not blocked, but it's not nice.
|
@Yaytay |
Oh, I'm sorry, I'd missed all of those. |
Ok no problem. Glad they work for you. |
I want to create a map from properties using JavaPropsMapper, which works as long as the keys for the map don't contain dots.
I have something like this:
And when I run that through the JavaPropsMapper it falls over because it creates:
{"map":{"x":{"y":"y"}}}
when what I want is:
{"map":{"x.y":"y"}}
(I want to have domain names as keys)
It would be nice if there was some way to escape the dots in property names so that they weren't considered to be delimiters.
I could probably make this work by configuring a completely different delimiter, but that would just confuse anyone wanting to work with this.
Things I've tried, any of which would be an OK solution for me, are:
The text was updated successfully, but these errors were encountered: