Hi guys,

I might be missing the flowers for the trees here as I've been working with vibe.d for a long time. However, I cannot find a simple vibe.d way to do something that is extremely common when building API backends.

Say we have a User object that looks like this:

struct User {
    string name;
    string reference;
    int salary;
}

So in my my API I have a putUpdate method. This does the following:

  • Takes in a JSON structure with the updates
  • Prunes out anything that that user should not be able to update
  • Loads and deserialises the record from the database
  • Applies the JSON update structure to the record

So the first step and the third step are rather easy with vibe.d. The second step, pruning, I have written in a separate library, but there are plenty of tools to do this easily with vibe.d (Though the standard Json and Bson types could use the ability to merge and prune conveniently)

The final step is my biggest issue. There does not appear to be a way to deserialise partial data over the top of an existing record. The deserialize method replaces it's target completely.

The only solution I have at the moment is:

  • Load the original record in and serialise it to Json
  • Merge the Json updates (not part of vibe standard library as far as I can tell)
  • Deserialise the update back to the model

Although this works, it is a lot of effort to go to and something that has to be done in each API in the application. While it is wrapped in a class at the moment, the solution feels inefficient our models also contain an internal state (not serialised) which has to be saved and restored each time we do this.

I'm really hoping that I've either missed something in the vibe library, or somebody has a much cleaner way of doing this already?

Thanks for your help guys,

David.