7#include <Cutelyst/context.h>
8#include <Cutelyst/response.h>
10#include <QtCore/QJsonDocument>
11#include <QtCore/QJsonObject>
60 d->exposeMode = ViewJson::String;
67 d->exposeMode = ViewJson::StringList;
74 d->exposeMode = ViewJson::RegularExpression;
81 d->xJsonHeader = enable;
87 return d->xJsonHeader;
96 const QVariantHash stash = c->
stash();
98 switch (d->exposeMode) {
104 auto it = stash.constFind(d->exposeKey);
105 if (it != stash.constEnd()) {
112 QVariantHash exposedStash;
114 auto it = stash.constBegin();
115 while (it != stash.constEnd()) {
117 if (d->exposeKeys.contains(key)) {
118 exposedStash.insert(key, it.value());
125 case RegularExpression:
127 QVariantHash exposedStash;
130 auto it = stash.constBegin();
131 while (it != stash.constEnd()) {
134 exposedStash.insert(key, it.value());
144 if (d->xJsonHeader && c->request()->
headers().
contains(QStringLiteral(
"X_PROTOTYPE_VERSION"))) {
146 QStringLiteral(
"eval(\"(\"+this.transport.responseText+\")\")"));
154#include "moc_viewjson.cpp"
void stash(const QVariantHash &unite)
Response * response() const noexcept
Headers headers() const noexcept
void setHeader(const QString &field, const QString &value)
void setContentType(const QString &type)
void setOutputFormat(JsonFormat format)
void setExposeStash(const QString &key)
JsonFormat outputFormat() const
QByteArray render(Context *c) const final
ViewJson(QObject *parent, const QString &name=QString())
ExposeMode exposeStashMode() const
void setXJsonHeader(bool enable)
View(QObject *parent, const QString &name)
The Cutelyst namespace holds all public Cutelyst API.
QByteArray toJson() const const
QJsonObject fromVariantHash(const QVariantHash &hash)
iterator insert(const QString &key, const QJsonValue &value)
QJsonValue fromVariant(const QVariant &variant)
QObject * parent() const const
QRegularExpressionMatch match(const QString &subject, int offset, MatchType matchType, MatchOptions matchOptions) const const
bool hasMatch() const const