https://kotlinlang.org logo
#kotest
Title
# kotest
j

Jgafner

08/09/2021, 9:41 AM
Hi In our project we have multiple json file in a tests resources folder we would like to deserialize during the tests Is there a Kotes framework that help doing that ? I found a way to read a specific file with a specific name but since we have many and we can add more - I would like to iterate over the folder (not nested) Thanks
s

sam

08/09/2021, 10:56 AM
You would just use jackson or some other json parser right?
j

Jgafner

08/09/2021, 10:56 AM
yes
s

sam

08/09/2021, 10:56 AM
So does that answer your question
j

Jgafner

08/09/2021, 10:58 AM
My question was more on how to collect all the files in a specific resource folder to parse laster by the jackson framework
I saw in TornadoFX they got some nice utils for that so I was wondering if there is one in kotest as well
s

sam

08/09/2021, 10:59 AM
Can you show me the tornado stuff
j

Jgafner

08/09/2021, 11:02 AM
https://edvin.gitbooks.io/tornadofx-guide/content/part1/3_Components.html they added this:
Copy code
val resources: ResourceLookup by lazy {
    ResourceLookup(this)
}
so we can do something like this:
Copy code
val myJsonObject = resources.json("myobject.json")
in the page I sent under: Accessing Resources section
s

sam

08/09/2021, 11:06 AM
I see, that's not built into Kotest. I think its a little too specific to live in kotest, which doesn't have anything specific for json handling. You would be doing something like (in jackson)
mapper.readValue<Foo>(javaClass.getResourceAsStream("/myobject.json"))
I think you could add your own little wrapper very easily
j

Jgafner

08/09/2021, 11:06 AM
ok tnx a lot
4 Views