Skip to content

Commit

Permalink
Handle JSON QVariantMap OGR write
Browse files Browse the repository at this point in the history
Fix #52677
  • Loading branch information
elpaso committed Apr 19, 2023
1 parent f35a0ba commit 6d07aac
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/core/qgsvectorfilewriter.cpp
Expand Up @@ -703,6 +703,18 @@ void QgsVectorFileWriter::init( QString vectorFileName,
break;
}

case QVariant::Map:
// handle GPKG conversion to JSON
if ( mOgrDriverName == QLatin1String( "GPKG" ) )
{
ogrType = OFTString;
ogrSubType = OFSTJSON;
break;
}

//intentional fall-through
FALLTHROUGH

case QVariant::List:
// handle GPKG conversion to JSON
if ( mOgrDriverName == QLatin1String( "GPKG" ) )
Expand Down Expand Up @@ -2923,6 +2935,25 @@ gdal::ogr_feature_unique_ptr QgsVectorFileWriter::createFeature( const QgsFeatur
//intentional fall-through
FALLTHROUGH

case QVariant::Map:
// handle GPKG conversion to JSON
if ( mOgrDriverName == QLatin1String( "GPKG" ) )
{
const QJsonDocument doc = QJsonDocument::fromVariant( attrValue );
QString jsonString;
if ( !doc.isNull() )
{
const QByteArray json { doc.toJson( QJsonDocument::Compact ) };
jsonString = QString::fromUtf8( json.data() );
}
OGR_F_SetFieldString( poFeature.get(), ogrField, mCodec->fromUnicode( jsonString.constData() ) );
break;
}

//intentional fall-through
FALLTHROUGH


default:
mErrorMessage = QObject::tr( "Invalid variant type for field %1[%2]: received %3 with type %4" )
.arg( mFields.at( fldIdx ).name() )
Expand Down

0 comments on commit 6d07aac

Please sign in to comment.