diff --git a/src/core/qgsfield.cpp b/src/core/qgsfield.cpp index 74671f22def3..0b37afd2cc86 100644 --- a/src/core/qgsfield.cpp +++ b/src/core/qgsfield.cpp @@ -257,11 +257,8 @@ QString QgsField::displayString( const QVariant &v ) const } else if ( d->typeName.compare( "json" ) == 0 || d->typeName.compare( "jsonb" ) == 0 ) { - //this works only if the json/jsonb field contains a map - this has to be improved. - //toJsonDocument works only if the usertype is QJsonDocument - QJsonValue value = QJsonValue::fromVariant( v ); - QJsonDocument doc( value.toObject() ); - return QString::fromUtf8( doc.toJson( QJsonDocument::Indented ).data() ); + QJsonDocument doc = QJsonDocument::fromVariant( v ); + return QString::fromUtf8( doc.toJson().data() ); } // Fallback if special rules do not apply return v.toString(); diff --git a/src/providers/postgres/qgspostgresconn.cpp b/src/providers/postgres/qgspostgresconn.cpp index 45e0b74f2bfa..67986d50ebad 100644 --- a/src/providers/postgres/qgspostgresconn.cpp +++ b/src/providers/postgres/qgspostgresconn.cpp @@ -989,7 +989,7 @@ static QString doubleQuotedMapValue( const QString &v ) static QString quotedMap( const QVariantMap &map ) { - //should it be stored in json/jsonb as well? + //to store properly it should be decided if it's a hstore or a json/jsonb field here... QString ret; for ( QVariantMap::const_iterator i = map.constBegin(); i != map.constEnd(); ++i ) { diff --git a/src/providers/postgres/qgspostgresprovider.cpp b/src/providers/postgres/qgspostgresprovider.cpp index bc0bdf51980f..a3522533f05a 100644 --- a/src/providers/postgres/qgspostgresprovider.cpp +++ b/src/providers/postgres/qgspostgresprovider.cpp @@ -2132,9 +2132,10 @@ bool QgsPostgresProvider::addFeatures( QgsFeatureList &flist, Flags flags ) .arg( delim, quotedValue( v.toString() ) ); } - //TODO: convert arrays and hstore to native types and json/jsonb + //TODO: convert arrays and hstore to native types else { + //this should be for json/jsonb in future values += delim + quotedValue( v ); } } @@ -3709,8 +3710,9 @@ bool QgsPostgresProvider::convertField( QgsField &field, const QMap