Skip to content

Serialize new formatter#83

Merged
schveiguy merged 2 commits into
masterfrom
serialize-new-formatter
Jun 6, 2026
Merged

Serialize new formatter#83
schveiguy merged 2 commits into
masterfrom
serialize-new-formatter

Conversation

@schveiguy

Copy link
Copy Markdown
Owner

Use the new formatter system to do serialization

schveiguy added 2 commits May 25, 2026 15:00
* Rename JSONOutputter -> JSONWriter
* Change all unittests in serializer to remove spacing
* Switch to using iopipe writeBuf function with default ReleaseOnWrite =
  true
* Update unittests in formatter.d to use ReleaseOnWrite.no to keep the
  output in the window
* Move jsonEscapeSubstitutions into formatter
* Add JSONWriterInterface and JSONWriterObject to to allow virtual
  functions to user JSON writer types.
* default serializer now has NO spacing in the output, use an
  appropriate formatter to make pretty-printed json. More options to be
  determined.
@schveiguy

Copy link
Copy Markdown
Owner Author

@Inkrementator wondering if you have some thoughts on this as a user with current code.

While redoing the serializer, there are some breaking changes here:

  1. The toJSON method now takes a policy and a formatter instead of just a char[] delegate. I found I had to do something a bit funky for this to be usable for class hierarchies (see the JSONWriterInterface and Object).
  2. The default format of the serializer was not very reasonable. Some spacing between commas and colons, but no indentation and newlines. I defaulted to zero spacing. The reason for this was twofold -- it was much easier to migrate the unittests to just remove spaces than add newlines and indentation; a common default is to use no spaces for transmission over networks.

Also value your feedback @gulugulubing!

I had some inclination to give back a delegate for some kind of scoped value writing for the virtual function setup, but after implementing it for a bit, I did not like how it worked.

Ideas on how to solve that problem welcome.

@schveiguy
schveiguy merged commit f0905cb into master Jun 6, 2026
6 checks passed
@schveiguy
schveiguy deleted the serialize-new-formatter branch June 6, 2026 18:20
@gulugulubing

gulugulubing commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

It looks good to me. It's much more symmetric with the deserialization side (Tokenizer for input ↔ Writer for output).
And on the virtual function setup, it seems fine, because the boilerplate only needs to be written once in the base class.

One minor thing — in serialize.d around the JSONValue Bool case, it looks like there might be a double-write. I fixed here #85

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants