~ubuntu-branches/ubuntu/oneiric/json-glib/oneiric

« back to all changes in this revision

Viewing changes to json-glib/json-gobject.c

  • Committer: Package Import Robot
  • Author(s): Martin Pitt
  • Date: 2011-09-12 09:08:07 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: package-import@ubuntu.com-20110912090807-3br793wiakn3yr8r
Tags: 0.13.90-1
* New upstream release.
* Drop 0001-Fix-GVariant-creation-on-some-architectures-bug-6504.patch:
  Applied upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
198
198
  members = json_object_get_members (object);
199
199
  members_left = NULL;
200
200
 
201
 
  /* first pass: construct and construct-only properties; here
202
 
   * we cannot use Serializable because we don't have an
203
 
   * instance yet; we use the default implementation of
204
 
   * json_deserialize_pspec() to deserialize known types
 
201
  /* first pass: construct-only properties; here we cannot use Serializable
 
202
   * because we don't have an instance yet; we use the default implementation
 
203
   * of json_deserialize_pspec() to deserialize known types
205
204
   *
206
 
   * FIXME - find a way to allow deserialization for these
207
 
   * properties
 
205
   * FIXME - find a way to allow deserialization for these properties
208
206
   */
209
207
  construct_params = g_array_sized_new (FALSE, FALSE, sizeof (GParameter), n_members);
210
208
 
232
230
      val = json_object_get_member (object, member_name);
233
231
      res = json_deserialize_pspec (&param.value, pspec, val);
234
232
      if (!res)
235
 
        g_value_unset (&param.value);
 
233
        {
 
234
          g_warning ("Failed to deserialize \"%s\" property of type \"%s\" for an object of type \"%s\"",
 
235
                     pspec->name, G_VALUE_TYPE_NAME (&param.value), g_type_name (gtype));
 
236
 
 
237
          g_value_unset (&param.value);
 
238
        }
236
239
      else
237
240
        {
238
241
          param.name = g_strdup (pspec->name);
302
305
        continue;
303
306
 
304
307
      /* we should have dealt with these above */
305
 
      if ((pspec->flags & G_PARAM_CONSTRUCT_ONLY) ||
306
 
          (pspec->flags & G_PARAM_CONSTRUCT))
 
308
      if (pspec->flags & G_PARAM_CONSTRUCT_ONLY)
307
309
        continue;
308
310
 
309
311
      if (!(pspec->flags & G_PARAM_WRITABLE))
400
402
      else
401
403
        g_object_get_property (gobject, pspec->name, &value);
402
404
 
403
 
      /* skip if the value is the default for the property */
404
 
      if (g_param_value_defaults (pspec, &value))
405
 
        {
406
 
          g_value_unset (&value);
407
 
          continue;
408
 
        }
409
 
 
410
405
      /* if there is a serialization vfunc, then it is completely responsible
411
406
       * for serializing the property, possibly by calling the implementation
412
407
       * of the default JsonSerializable interface through chaining up
417
412
                                            &value,
418
413
                                            pspec);
419
414
        }
420
 
      else
 
415
      /* skip if the value is the default for the property */
 
416
      else if (!g_param_value_defaults (pspec, &value))
421
417
        node = json_serialize_pspec (&value, pspec);
422
418
 
423
419
      if (node)
517
513
        {
518
514
        case G_TYPE_BOOLEAN:
519
515
        case G_TYPE_INT64:
520
 
        case G_TYPE_DOUBLE:
521
516
        case G_TYPE_STRING:
522
 
          g_value_copy (&node_value, value);
523
 
          retval = TRUE;
 
517
          if (G_VALUE_HOLDS (&node_value, G_VALUE_TYPE (value)))
 
518
            {
 
519
              g_value_copy (&node_value, value);
 
520
              retval = TRUE;
 
521
            }
524
522
          break;
525
523
 
526
524
        case G_TYPE_INT:
527
 
          g_value_set_int (value, (gint) g_value_get_int64 (&node_value));
528
 
          retval = TRUE;
 
525
          if (G_VALUE_HOLDS (&node_value, G_TYPE_INT64))
 
526
            {
 
527
              g_value_set_int (value, (gint) g_value_get_int64 (&node_value));
 
528
              retval = TRUE;
 
529
            }
529
530
          break;
530
531
 
531
532
        case G_TYPE_CHAR:
532
 
          g_value_set_char (value, (gchar) g_value_get_int64 (&node_value));
533
 
          retval = TRUE;
 
533
          if (G_VALUE_HOLDS (&node_value, G_TYPE_INT64))
 
534
            {
 
535
              g_value_set_char (value, (gchar) g_value_get_int64 (&node_value));
 
536
              retval = TRUE;
 
537
            }
534
538
          break;
535
539
 
536
540
        case G_TYPE_UINT:
537
 
          g_value_set_uint (value, (guint) g_value_get_int64 (&node_value));
538
 
          retval = TRUE;
 
541
          if (G_VALUE_HOLDS (&node_value, G_TYPE_INT64))
 
542
            {
 
543
              g_value_set_uint (value, (guint) g_value_get_int64 (&node_value));
 
544
              retval = TRUE;
 
545
            }
539
546
          break;
540
547
 
541
548
        case G_TYPE_UCHAR:
542
 
          g_value_set_uchar (value, (guchar) g_value_get_int64 (&node_value));
543
 
          retval = TRUE;
 
549
          if (G_VALUE_HOLDS (&node_value, G_TYPE_INT64))
 
550
            {
 
551
              g_value_set_uchar (value, (guchar) g_value_get_int64 (&node_value));
 
552
              retval = TRUE;
 
553
            }
 
554
          break;
 
555
 
 
556
        case G_TYPE_DOUBLE:
 
557
 
 
558
          if (G_VALUE_HOLDS (&node_value, G_TYPE_DOUBLE))
 
559
            {
 
560
              g_value_set_double (value, g_value_get_double (&node_value));
 
561
              retval = TRUE;
 
562
            }
 
563
          else if (G_VALUE_HOLDS (&node_value, G_TYPE_INT64))
 
564
            {
 
565
              g_value_set_double (value, (gdouble) g_value_get_int64 (&node_value));
 
566
              retval = TRUE;
 
567
            }
 
568
 
544
569
          break;
545
570
 
546
571
        case G_TYPE_FLOAT:
547
 
          g_value_set_float (value, (gfloat) g_value_get_double (&node_value));
548
 
          retval = TRUE;
 
572
          if (G_VALUE_HOLDS (&node_value, G_TYPE_DOUBLE))
 
573
            {
 
574
              g_value_set_float (value, (gfloat) g_value_get_double (&node_value));
 
575
              retval = TRUE;
 
576
            }
 
577
          else if (G_VALUE_HOLDS (&node_value, G_TYPE_INT64))
 
578
            {
 
579
              g_value_set_float (value, (gfloat) g_value_get_int64 (&node_value));
 
580
              retval = TRUE;
 
581
            }
 
582
 
549
583
          break;
550
584
 
551
585
        case G_TYPE_ENUM: