<table><tr><td style="">dvratil added a comment.
</td><a style="text-decoration: none; padding: 4px 8px; margin: 0 8px 8px; float: right; color: #464C5C; font-weight: bold; border-radius: 3px; background-color: #F7F7F9; background-image: linear-gradient(to bottom,#fff,#f1f0f1); display: inline-block; border: 1px solid rgba(71,87,120,.2);" href="https://phabricator.kde.org/D13104">View Revision</a></tr></table><br /><div><div><p>To clarify what I mean, right now you have to do <tt style="background: #ebebeb; font-size: 13px;">static_cast<Command*>(cmd)->toJson()</tt> which will internally cast down and do the serialization. If you do</p>

<div class="remarkup-code-block" style="margin: 12px 0;" data-code-lang="text" data-sigil="remarkup-code-block"><pre class="remarkup-code" style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; padding: 12px; margin: 0; background: rgba(71, 87, 120, 0.08);">FetchItemsCommandPtr fetchCmd = cmd.staticCast<FetchItemsCommand>(cmd);
fetchCmd->toJson();</pre></div>

<p>you will get an incomplete serialization because <tt style="background: #ebebeb; font-size: 13px;">FetchItemsCommand::toJson()</tt> won't internally chain up to <tt style="background: #ebebeb; font-size: 13px;">Command::toJson()</tt>. This is why I suggested that you should handle the chain up internally inside <tt style="background: #ebebeb; font-size: 13px;">toJson()</tt> using <tt style="background: #ebebeb; font-size: 13px;">ClassNode::parentClassName()</tt> like we do in <tt style="background: #ebebeb; font-size: 13px;">operator<<(QDebug)</tt>. However this way you can still get incomplete serialization if you do something like this:</p>

<div class="remarkup-code-block" style="margin: 12px 0;" data-code-lang="text" data-sigil="remarkup-code-block"><pre class="remarkup-code" style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; padding: 12px; margin: 0; background: rgba(71, 87, 120, 0.08);">CommandPtr cmd = fetchCmd;
cmd->toJson();</pre></div>

<p>In order to handle that, we would have <tt style="background: #ebebeb; font-size: 13px;">Protocol::toJson()</tt> that would internally down-cast to the leaf-type and call <tt style="background: #ebebeb; font-size: 13px;">toJson()</tt> on it, which would then internally chain up. This would be consistent with how you use the <tt style="background: #ebebeb; font-size: 13px;">Protocol::debugString()</tt> to get a debug string.</p></div></div><br /><div><strong>REPOSITORY</strong><div><div>R165 Akonadi </div></div></div><br /><div><strong>REVISION DETAIL</strong><div><a href="https://phabricator.kde.org/D13104">https://phabricator.kde.org/D13104</a></div></div><br /><div><strong>To: </strong>knauss, dvratil<br /><strong>Cc: </strong>kde-pim, dvasin, rodsevich, winterz, vkrause, mlaurent, knauss, dvratil<br /></div>