Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PIM
KItinerary
Commits
909055b1
Commit
909055b1
authored
Sep 19, 2021
by
Volker Krause
Browse files
Recover missing JSON-LD @type information from our own type knowledge
This fixes reading Flixtrain seat information for example.
parent
731b0780
Pipeline
#81467
passed with stage
in 13 minutes and 43 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/lib/jsonlddocument.cpp
View file @
909055b1
...
...
@@ -115,6 +115,7 @@ static void registerBuiltInTypes(std::vector<TypeInfo> &r)
}
static
QVariant
createInstance
(
const
QJsonObject
&
obj
);
static
QVariant
createInstance
(
const
QJsonObject
&
obj
,
const
QMetaProperty
&
prop
);
// Eurowings workarounds...
static
const
char
*
const
fallbackDateTimePattern
[]
=
{
...
...
@@ -241,7 +242,7 @@ static QVariant propertyValue(const QMetaProperty &prop, const QJsonValue &v)
if
(
prop
.
userType
()
==
qMetaTypeId
<
QVariant
>
()
&&
isEmptyJsonLdObject
(
obj
))
{
return
{};
}
return
createInstance
(
obj
);
return
createInstance
(
obj
,
prop
);
}
static
void
createInstance
(
const
QMetaObject
*
mo
,
void
*
v
,
const
QJsonObject
&
obj
)
...
...
@@ -261,10 +262,8 @@ static void createInstance(const QMetaObject *mo, void *v, const QJsonObject &ob
}
}
static
QVariant
createInstance
(
const
QJsonObject
&
obj
)
static
QVariant
createInstance
(
const
QJsonObject
&
obj
,
const
QString
&
type
)
{
const
auto
type
=
obj
.
value
(
QLatin1String
(
"@type"
)).
toString
();
const
auto
&
registry
=
typeResgistry
();
const
auto
it
=
std
::
lower_bound
(
registry
.
begin
(),
registry
.
end
(),
type
,
[](
const
auto
&
lhs
,
const
auto
&
rhs
)
{
return
QLatin1String
(
lhs
.
name
)
<
rhs
;
...
...
@@ -284,6 +283,29 @@ static QVariant createInstance(const QJsonObject &obj)
return
{};
}
static
QVariant
createInstance
(
const
QJsonObject
&
obj
)
{
return
createInstance
(
obj
,
obj
.
value
(
QLatin1String
(
"@type"
)).
toString
());
}
static
QVariant
createInstance
(
const
QJsonObject
&
obj
,
const
QMetaProperty
&
prop
)
{
const
auto
type
=
obj
.
value
(
QLatin1String
(
"@type"
)).
toString
();
if
(
!
type
.
isEmpty
())
{
return
createInstance
(
obj
,
type
);
}
// if @type is (wrongly) not specified, try to recover from our own knowledge of a property type
const
auto
mo
=
QMetaType
::
metaObjectForType
(
prop
.
userType
());
if
(
mo
)
{
QVariant
value
(
prop
.
userType
(),
nullptr
);
createInstance
(
mo
,
value
.
data
(),
obj
);
return
value
;
}
return
{};
}
QVector
<
QVariant
>
JsonLdDocument
::
fromJson
(
const
QJsonArray
&
array
)
{
QVector
<
QVariant
>
l
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment