ImagingTools Core SDK
Public Member Functions | List of all members
imtdb::IJsonBasedMetaInfoDelegateabstract

Converts document metadata to/from JSON representation. More...

#include <IJsonBasedMetaInfoDelegate.h>

Inherits istd::IPolymorphic.

Inherited by imtdbgql::TSdlBasedMetaInfoDelegate< sdl::controlsgallery::ContactInfos::CContactInfoItemData::V1_0 > [virtual], imtdb::CJsonBasedMetaInfoDelegateComp [virtual], and imtdbgql::TSdlBasedMetaInfoDelegate< MetaInfoRepresentation > [virtual].

Public Member Functions

virtual bool ToJsonRepresentation (const idoc::IDocumentMetaInfo &metaInfo, QByteArray &json, const QByteArray &typeId) const =0
 Converts metadata to JSON representation.
 
virtual bool FromJsonRepresentation (const QByteArray &json, idoc::IDocumentMetaInfo &metaInfo, const QByteArray &typeId) const =0
 Creates metadata from JSON representation.
 

Detailed Description

Converts document metadata to/from JSON representation.

IJsonBasedMetaInfoDelegate provides bidirectional conversion between structured metadata (IDocumentMetaInfo) and JSON format for database storage. This enables rich, schema-less metadata to be persisted in JSON/JSONB database columns.

Purpose

Metadata in imtdb applications includes:

This interface standardizes the JSON schema for metadata storage, ensuring consistency across different components and enabling JSON-based queries.

JSON Schema

Typical metadata JSON structure:

{
"customFields": {
"priority": "high",
"category": "bug-fix"
},
"tags": ["urgent", "security"],
"dependentRefs": {
"parentIssue": "issue-123",
"relatedUsers": ["user-1", "user-2"]
},
"revisionInfo": {
"revisionNumber": 5,
"lastModifiedBy": "user-admin",
"timestamp": "2024-01-15T10:30:00Z"
}
}

Implementations

Usage Example

auto delegate = acf::CreateComponent<CJsonBasedMetaInfoDelegateComp>();
// Serialize metadata to JSON for database storage
auto metaInfo = acf::CreateComponent<CDocumentMetaInfoComp>();
metaInfo->SetValue("priority", "high");
metaInfo->SetValue("category", "bug-fix");
QByteArray typeId = "MyDocumentType";
QByteArray json;
if (delegate->ToJsonRepresentation(*metaInfo, json, typeId)) {
// Store json in database JSONB column
}
// Deserialize metadata from database
QByteArray storedJson = ...; // from database
auto loadedMetaInfo = acf::CreateComponent<CDocumentMetaInfoComp>();
if (delegate->FromJsonRepresentation(storedJson, *loadedMetaInfo, typeId)) {
QString priority = loadedMetaInfo->GetValue("priority").toString();
}
Note
The JSON schema is versioned to support migrations
Implementations must handle forward/backward compatibility
See also
CJsonBasedMetaInfoDelegateComp for base implementation
idoc::IDocumentMetaInfo for the metadata interface

Definition at line 89 of file IJsonBasedMetaInfoDelegate.h.

Member Function Documentation

◆ FromJsonRepresentation()

virtual bool imtdb::IJsonBasedMetaInfoDelegate::FromJsonRepresentation ( const QByteArray &  json,
idoc::IDocumentMetaInfo &  metaInfo,
const QByteArray &  typeId 
) const
pure virtual

Creates metadata from JSON representation.

Deserializes a JSON byte array into an IDocumentMetaInfo object, parsing the JSON according to the delegate's schema and populating the metadata with fields and values.

Parameters
jsonThe JSON byte array to parse (UTF-8 encoded)
[out]metaInfoReceives the deserialized metadata
typeIdThe type identifier of the document being deserialized
Returns
true if parsing and population succeeded, false on error
Note
Invalid JSON returns false and leaves metaInfo unchanged
Missing fields in JSON result in absent fields in metaInfo
Extra fields in JSON may be ignored or cause errors depending on implementation
The typeId parameter allows type-specific deserialization logic

Example:

QByteArray json = R"({"status":"active","priority":10})";
auto metaInfo = acf::CreateComponent<CDocumentMetaInfoComp>();
QByteArray typeId = "MyDocumentType";
if (delegate->FromJsonRepresentation(json, *metaInfo, typeId)) {
QString status = metaInfo->GetValue("status").toString(); // "active"
int priority = metaInfo->GetValue("priority").toInt(); // 10
}
See also
ToJsonRepresentation()

◆ ToJsonRepresentation()

virtual bool imtdb::IJsonBasedMetaInfoDelegate::ToJsonRepresentation ( const idoc::IDocumentMetaInfo &  metaInfo,
QByteArray &  json,
const QByteArray &  typeId 
) const
pure virtual

Converts metadata to JSON representation.

Serializes an IDocumentMetaInfo object to a JSON byte array following the delegate's JSON schema. The resulting JSON can be stored in database JSONB/JSON columns.

Parameters
metaInfoThe metadata object to serialize
[out]jsonReceives the JSON representation (UTF-8 encoded)
typeIdThe type identifier of the document being serialized
Returns
true if serialization succeeded, false on error
Note
The JSON is compact (no formatting) for efficient storage
NULL or empty metadata may produce empty JSON object "{}"
The typeId parameter allows type-specific serialization logic

Example:

auto metaInfo = acf::CreateComponent<CDocumentMetaInfoComp>();
metaInfo->SetValue("status", "active");
metaInfo->SetValue("tags", QStringList{"important", "reviewed"});
QByteArray json;
QByteArray typeId = "MyDocumentType";
delegate->ToJsonRepresentation(*metaInfo, json, typeId);
// json contains: {"status":"active","tags":["important","reviewed"]}
See also
FromJsonRepresentation()