rocketraman
11/14/2023, 2:47 PMPATCH
is impossible to do with the same types, because the incoming data is incomplete, so even if the server-side code can deserialize it (unlikely), we still need to know which subset of fields was actually sent by the client.
I had implemented https://github.com/rocketraman/kpropmap to deal with these scenarios in the past. The idea is to receive the data from the API in a flexible way, and then do validation and conversion to the strongly typed model on the server-side.
Any thoughts on introducing a similar capability to Akkurate? I've long wanted, but haven't had the time to have kpropmap use KSP and kotlinx-serialization rather than runtime reflection, and Akkurate already uses these tools.Johann Pardanaud
11/14/2023, 7:39 PMOne gap I see with using data classes in API interfaces is that immutable […] data classes aren't often a great fit for receiving "messy" data at the API level.I always demonstrate Akkurate with data classes because I think it's better this way. But, actually, you can also work with simple classes. Do you mind telling me if you thought about Akkurate being limited to data classes? If so, I will try to clarify this in the documentation.
Furthermore, errors can be thrown in advance of validationYou're right, and this is something where Akkurate can't help, unfortunately. However, there are some ways to mitigate some of the issues you mention: • configuring kotlinx.serialization to ignore unknown properties • providing default values for your properties to allow partial payloads • and since you don't want to "introduce some noise into the data model", you can create DTOs (yes, you will have to map them 😕) I know I'm not really answering to your requests there… but Akkurate hasn't been designed to work close to the HTTP payload, essentially to keep its API simple and to allow easy integration with other tools. However, I will keep in mind what you wrote here because you have valid points, and maybe one day I will find some way to improve Akkurate for those use cases. 🙂
rocketraman
11/14/2023, 8:53 PMJohann Pardanaud
11/14/2023, 10:02 PM