On 6/23/22 11:20 AM, Jesse Phillips wrote:
On Wednesday, 22 June 2022 at 01:09:22 UTC, Steven Schveighoffer wrote:

There are 3 situations:

1. field in json and struct. Obvious result.
2. field in json but not in struct.
3. field in struct but not in json.

I do a lot of reading JSON data in C#, and I heavily lean on optional over required.

The reason optional is so beneficial is because I'm looking to pull out specific data points from the JSON, I have no use nor care about any other field. If I had to specify every field being provided, every time something changes, the JSON parser would be completely unusable for me.

Well, my json parser is slightly different -- you don't need to serialize anything. The parser provides mechanisms to jump to some specific node in the json tree, and then you can deal with the data at that point.

It also provides a way to parse ahead and then rewind to a previous spot. All possible because iopipe has an expandable buffer. This is how I serialize classes where the class type is specified in an internal field.

The point of my philosophy on the UDA system is that you should have to opt-in to discrepancies in the data. Yes, it can be a pain, but I'd rather it be explicit.


I do like the @extra assuming it allows reserializing the entire JSON object. But many times that data just isn't needed and I'd like my type to trim it.

I could probably add a specialized type that just throws everything away, and tag that as @extras. Like:

```d
@extras Trash _;
```

Or something similar, to make it easier.

-Steve

Reply via email to