maxmello04/11/2020, 3:18 PM
. But when a model is stored in a database and edited in a frontend, we (de-)serialize the model, which removes the usefulness of
, because objects are newly created when deserialized (e.g. from a JSON request body). In my
endpoints, I want to make sure only the fields are updated which are actually mutable, so right now I manually get the old version of the model from the database and update mutable fields one by one manually from the new instance. For me, this has 2 problems: If I only update the var fields, the client might wonder why the other fields did not update on the next request. Secondly, when the model changes, it is easy to forget updating the manual updating code. Anybody got a better approach to this? Do you prever PUT endpoints per mutable property instead?
Shawn04/11/2020, 3:44 PM
But when a model is stored in a database and edited in a frontend, we (de-)serialize the model, which removes the usefulness ofthis is a common misconception. there are in fact libraries that will let you deserialize to classes with val properties, see, because objects are newly created when deserialized (e.g. from a JSON request body)
for an example
maxmello04/11/2020, 6:16 PM
Shawn04/11/2020, 6:30 PM
araqnid04/13/2020, 12:41 PM
Johannes Zick04/14/2020, 8:00 AM
David Eriksson04/15/2020, 9:00 AM
Eamonn04/16/2020, 1:28 PM
maxmello04/16/2020, 3:17 PM
which I can call on the existing model from the database, pass the one from the API call and in there decide what is allowed to be updated. It’s still not as clean as DTOs, so maybe I will change it in the future. Also true that it is not very Kotlin specific, I should have posted it in #random or thought about it more myself before posting at all.
open fun updateModel(newModel)