I understand the homogenous part when you do decoding, but encoding to json 
should support the homogenous, isn’t? why not? I understand that the decode of 
that json would alter the type.

QList<QVariantMap> • encode json • [{‘a’: ‘b’}, {‘c’:’d’}] • decode json • 
QList<QVariant>

Should be possible as long as QList<T> where T can be convert to QVariant. 
Maybe an external converter function should be used. If this is not supported, 
is there a way where we could trap this at compile time warning?

Maybe there is a limitation I do not see here.


From: Interest <interest-boun...@qt-project.org> on behalf of Thiago Macieira 
<thiago.macie...@intel.com>
Date: Wednesday, June 9, 2021 at 10:08 AM
To: interest@qt-project.org <interest@qt-project.org>
Subject: Re: [Interest] QJsonDocument::fromVariant failing with list
On Wednesday, 9 June 2021 00:34:40 PDT Allan Sandfeld Jensen wrote:
> > QList is not a type, it's a template. Neither QVariant nor QJsonDocument
> > can know all possible QList instantiations. So they have coded only a few
> > (QVariantList and QStringList only, possibly QVector<QVariant> and
> > QVector<QString> in Qt 5 too, I don't remember).
>
> I guess our system could detect QList<QVariant> as QVariantList and
> QList<QString> as QStringList. They should be binary identical anyway.

They already do.

The problem is QList of other things that it's not coded for, like
QList<QVariantMap> in this case, or QList<int> or QList<bool>. Since JSON
arrays are not expected to be homogeneous, QJsonDocument does not support
them.

--
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel DPG Cloud Engineering



_______________________________________________
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest
_______________________________________________
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest

Reply via email to