6 #include "validatorjson_p.h"
9 #include <QJsonDocument>
10 #include <QJsonObject>
11 #include <QJsonParseError>
19 :
ValidatorRule(*new ValidatorJsonPrivate(field, expectedType, messages, defValKey))
40 qCDebug(C_VALIDATOR).noquote()
41 <<
debugString(c) <<
"A JSON array is expected but not provided";
44 qCDebug(C_VALIDATOR).noquote()
45 <<
debugString(c) <<
"A JSON object is expected but not provided";
47 switch (d->expectedType) {
79 return c->
qtTrId(
"cutelyst-valjson-genvalerr-exparray");
83 return c->
qtTrId(
"cutelyst-valjson-genvalerr-exparray-label");
88 return c->
qtTrId(
"cutelyst-valjson-genvalerr-expobject");
92 return c->
qtTrId(
"cutelyst-valjson-genvalerr-expobject-label");
101 return c->
qtTrId(
"cutelyst-valjson-genvalerr-data").
arg(jsonError);
104 return c->
qtTrId(
"cutelyst-valjson-genvalerr");
110 return c->
qtTrId(
"cutelyst-valjson-genvalerr-data-label").
arg(_label, jsonError);
114 return c->
qtTrId(
"cutelyst-valjson-genvalerr-label").
arg(_label);
QString qtTrId(const char *id, int n=-1) const
Checks if the inut data is valid JSON.
~ValidatorJson() override
ValidatorReturnType validate(Context *c, const ParamsMultiMap ¶ms) const override
QString genericValidationError(Context *c, const QVariant &errorData=QVariant()) const override
ValidatorJson(const QString &field, ExpectedType expectedType=ExpectedType::All, const ValidatorMessages &messages=ValidatorMessages(), const QString &defValKey=QString())
Base class for all validator rules.
QString validationError(Context *c, const QVariant &errorData={}) const
QString label(Context *c) const
void defaultValue(Context *c, ValidatorReturnType *result) const
QString value(const ParamsMultiMap ¶ms) const
QString debugString(Context *c) const
The Cutelyst namespace holds all public Cutelyst API.
QJsonArray array() const const
QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error)
bool isArray() const const
bool isObject() const const
QJsonObject object() const const
QString errorString() const const
QString arg(Args &&... args) const const
bool isEmpty() const const
QByteArray toUtf8() const const
bool isNull() const const
void setValue(QVariant &&value)
QString toString() const const
Stores custom error messages and the input field label.
Contains the result of a single input parameter validation.