val filesystem: Environment = Environment.from(File("test.yml"))
var testString
var testStringLens: BiDiLens<Environment, String?> = EnvironmentKey.string().optional("TESTKEY")
testString = environment[testStringLens]
Only returns the string up to the first comma.
Example: (yml)
TESTKEY: “test1 , test2”
Example: (properties)
TESTKEY= “test1, test2"
Will only return test1 as the string.
How do I solve this? do I need to escape the string somehow?
I’m trying to actually read a json from a file under a key.
Razi Kheir
07/10/2019, 6:49 AM
I used multi and joined them as string but I wonder if that is okay to do like that, I mean I got the result, but is the method okay..
s
s4nchez
07/10/2019, 6:52 AM
I think you're right that this does not behave as expected:
Copy code
val lens = EnvironmentKey.optional("SOME_VALUE")
assertThat(lens(Environment.from("SOME_VALUE" to "80,81")), equalTo("80,81"))
This assertion currently fails with actual being
80
rather than
80,81
So I say for now use the multi and we'll look into why we're getting such behaviour
👍 1
r
Razi Kheir
07/10/2019, 6:52 AM
Thanks for the help
s
s4nchez
07/10/2019, 6:53 AM
You're welcome 🙂 Sorry for the trouble
r
Razi Kheir
07/10/2019, 6:56 AM
No trouble, thanks for the library
d
dave
07/10/2019, 7:35 AM
Not obvious, but expected. The default separator is a comma in environments. You can override it when you create the environment and it should work as you need.
dave
07/10/2019, 7:37 AM
This is totally to do with the way that lenses are constructed. A singular lens will extract the first only value from the "list". Eg with headers it will just grab the first instance of the header that it finds even though there may be multiple