Is there a library that serializes data classes in...
# announcements
a
Is there a library that serializes data classes into compilable Kotlin code? Something like this:
Copy code
data class Thing(val color: String, val shape: String)

val myThing = Thing("Red", "Square")
Copy code
serializeToSourceCode(myThing)

output:
Thing(color="Red", shape="Square")
k
huh?
a
@Kroppeb what do you mean?
k
So you want to print a representation that is valid Kotlin code that would generate the originial object?
a
yes. The context: I am replacing an API call with a mock.
Capturing the call's parameters, and what it returns, and spitting out:
k
Not really possible. The issue is that you'd have to do this recursive. In Python this would be somewhat possible.
I don't understand why you would need this for mock
Maybe #mockk can help you?
a
Copy code
every { myApi.callMethod(1, Thing("Red", "Square") } returns LocalDate.of(2020, 4, 30)
So I need to generate these mockk calls
Yes I know this needs to be recursive. And I know this is doable. Just don't want to write it if there already is something.
Thank you for a quick reply!
regarding "Maybe #mockk can help you?" of course it will, I am using
mockk
, I just don't want to type it manually.
too much work
k
I mean, maybe people in that channel know an other way to solve your problem
Might be something that happens often
a
Got it thank you so much!