On Tue, 06 Mar 2018 16:08:41 GMT, Stephan Dilly wrote:

so i have an external API that I would like to talk to using the restclientinterface system.

the POST endpoint expects a Json object like {template:2} now my problem is that sometimes the endpoint expects the object to look like this {text:"foo"}

this body object:

struct Obj
  @optional int template;
  @optional string text;

but it does not cut it because then the other parameter will still always be send and the API complains if that happens. so how am I supposed to use that same API endpoint without defining lots of dupication in the structs (of course they have many more members who are always supposed to be in there) and duplicated endpoints even though the path is always the same? For the record I tried Nullable!... already, that in fact sends them as null which the API still does not appreciate - its wants them gone entirely :D

Is there a DontSerializeWhenNull!... macro for this in Json or something along the lines? Or am I missing something?


There is https://github.com/vibe-d/vibe.d/pull/1650, which should really be pushed forward, but I lost track of it at some point.

A possible workaround would be to define Json toJson and static Obj fromJson(Json) methods that customize the returned JSON. That would require quite a bit of boilerplate code, but at least it is just in a single place.