Allow extension of details::serializer #4221
Replies: 1 comment
-
OK, I've had time to flesh this out and implement it (& unit test) to, at least, achieve what I wanted to do (essentially the request of #4171), but it can also help for #4131 (I think, I haven't fully thought it through) and #3022. With a little bit of additional change, #2711 can also be resolved. @nlohmann noted in #3022 that it's difficult to create an API that can handle all of the tweaks people would like in their dump output. Allowing limited modifications to the dump serializer allows everyone to implement their own tweaks. Then the serializer can be passed to dump. Since the serializer is a new interface to the public, the API for the serializer can be constructed from scratch. For now, I've aimed for minimal changes, but fully realizing this would require further modifications. For the serializer, I have not made any private members protected, so the various New & modified changes to
Within Within
In each, the function creates the appropriate There are some other issues to work out, but I didn't want to go down that rabbit hole if you don't feel this to be a worthwhile path. |
Beta Was this translation helpful? Give feedback.
-
There are several ideas on here related to modifying the
dump
output. Currently, the only option is to create your own, although much of the hard work was already done indetails::serializer
. If we could extend it, that'd be great. If we could pass that modified serializer todump
andoperator<<
.At minimum, making
serializer::dump
virtual, and switching some of the private variables & functions to protected would be helpful.With some additional changes in how the serializer is constructed (notably, supplying the output adapter after construction, within
dump
oroperator<<
), this could also help the concerns noted in #4117.If you have concerns about people mucking with the representation of the non-aggregate types, you can have virtual functions just for the output of objects & arrays.
Beta Was this translation helpful? Give feedback.
All reactions