On 2/12/21 6:22 PM, Chris Bare wrote:
I'm working on a project with vibe.d and ddbc to access my database.
Both have powerful functions that operate on Struct types to avoid a lot
of boilerplate code.
I have a web site that sends a json message to update a record.
deserializeJson creates a new Foo record containing the json data.
However, there are some fields in the record which are not in the json,
and these get default values.
I have another Foo that has the original values.
What would be the best way to merge the updated values into the original?
Obviously I can copy from one Foo to the other, but that's pretty
inelegant.
If I could pass an existing Foo to deserializeJson and have only some
fields filled in, that would be perfect.
I tried this:
deserializeJson!Foo(foo, req.json);
but it completely overwrites all the fields in foo.
Any suggestions? Is there a trick I'm just not seeing?
Does @ignore work? That's a UDA that tells vibe to ignore the field.
Though I don't know if it means it leaves it alone completely.
https://vibed.org/api/vibe.data.serialization/ignore
-Steve