[tracker/wip/sam/resource] libtracker-sparql: Output arrays of values to JSON
- From: Sam Thursfield <sthursfield src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/sam/resource] libtracker-sparql: Output arrays of values to JSON
- Date: Fri, 8 Apr 2016 23:47:10 +0000 (UTC)
commit 0ae2137be3cbcb49021d519aa1c15adc39bef625
Author: Sam Thursfield <ssssam gmail com>
Date: Sat Apr 9 00:46:39 2016 +0100
libtracker-sparql: Output arrays of values to JSON
src/libtracker-sparql/tracker-resource.c | 46 ++++++++++++++++++-----------
1 files changed, 28 insertions(+), 18 deletions(-)
---
diff --git a/src/libtracker-sparql/tracker-resource.c b/src/libtracker-sparql/tracker-resource.c
index 18eb374..b2c74c0 100644
--- a/src/libtracker-sparql/tracker-resource.c
+++ b/src/libtracker-sparql/tracker-resource.c
@@ -575,23 +575,12 @@ tracker_resource_generate_jsonld (TrackerResource *self,
};
static void
-generate_jsonld_foreach (gpointer key,
- gpointer value_ptr,
- gpointer user_data)
+append_value_to_json_builder (const GValue *value,
+ JsonBuilder *builder)
{
- const char *property = key;
- const GValue *value = value_ptr;
- JsonBuilder *builder = JSON_BUILDER (user_data);
JsonNode *node;
- /* FIXME: shouldn't hardcode the unexpanded prefix here!!! */
- if (strcmp (property, "rdf:type") == 0) {
- property = "@type";
- }
-
- if (G_VALUE_HOLDS (value, G_TYPE_PTR_ARRAY)) {
- g_warning ("Not serializing property %s: arrays not yet implemented.", property);
- } else if (G_VALUE_HOLDS (value, TRACKER_TYPE_RESOURCE)) {
+ if (G_VALUE_HOLDS (value, TRACKER_TYPE_RESOURCE)) {
TrackerResource *resource;
GError *error = NULL;
@@ -599,10 +588,9 @@ generate_jsonld_foreach (gpointer key,
node = tracker_resource_generate_jsonld (resource, &error);
if (node) {
- json_builder_set_member_name (builder, property);
json_builder_add_value (builder, node);
} else {
- g_warning ("Unable to serialize value of %s: %s", property, error->message);
+ g_warning ("Unable to serialize value: %s", error->message);
g_error_free (error);
}
} else if (G_VALUE_HOLDS (value, TRACKER_TYPE_URI)) {
@@ -614,16 +602,38 @@ generate_jsonld_foreach (gpointer key,
const char *uri = g_value_get_string (value);
node = json_node_new (JSON_NODE_VALUE);
json_node_set_string (node, uri);
- json_builder_set_member_name (builder, property);
json_builder_add_value (builder, node);
} else {
node = json_node_new (JSON_NODE_VALUE);
json_node_set_value (node, value);
- json_builder_set_member_name (builder, property);
json_builder_add_value (builder, node);
}
}
+static void
+generate_jsonld_foreach (gpointer key,
+ gpointer value_ptr,
+ gpointer user_data)
+{
+ const char *property = key;
+ const GValue *value = value_ptr;
+ JsonBuilder *builder = JSON_BUILDER (user_data);
+
+ /* FIXME: shouldn't hardcode the unexpanded prefix here!!! */
+ if (strcmp (property, "rdf:type") == 0) {
+ property = "@type";
+ }
+
+ json_builder_set_member_name (builder, property);
+ if (G_VALUE_HOLDS (value, G_TYPE_PTR_ARRAY)) {
+ json_builder_begin_array (builder);
+ g_ptr_array_foreach (g_value_get_boxed (value), (GFunc) append_value_to_json_builder,
builder);
+ json_builder_end_array (builder);
+ } else {
+ append_value_to_json_builder (value, builder);
+ }
+}
+
/**
* tracker_resource_print_jsonld:
* @resource: a #TrackerResource
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]