digitalmars.D.learn - vibe.d json deserializeJson!Foo and ddbc.update!Foo
- Chris Bare (21/21) Feb 12 2021 I'm working on a project with vibe.d and ddbc to access my
- Steven Schveighoffer (5/26) Feb 12 2021 Does @ignore work? That's a UDA that tells vibe to ignore the field.
- Chris Bare (5/12) Feb 13 2021 @ignore just prevents it from throwing an error if the field is
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? -- Chris
Feb 12 2021
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
Feb 12 2021
On Saturday, 13 February 2021 at 01:21:56 UTC, Steven Schveighoffer wrote:On 2/12/21 6:22 PM, Chris Bare wrote:ignore just prevents it from throwing an error if the field is not in the json. The field still gets overwritten with it's default value in the struct.[...]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
Feb 13 2021