[Vala] De/serializing Classes into Json
- From: Johann Weging <johann weging net>
- To: vala-list gnome org
- Cc: Julian Kunkel <kunkel dkrz de>
- Subject: [Vala] De/serializing Classes into Json
- Date: Thu, 07 Feb 2013 17:24:15 +0100
Hello,
I'm trying to de/serialize a Vala class into Json with the glib-json-1.0 module.
A class like:
public class testClass : GLib.Object {
public int i{get;set;}
public int[] array {get;set;}
}
After setting some values the class should be serialized into:
{
i : 1,
array : [1,2,3]
}
What I tried so far:
Using the "object_to_data" and "object_from_data" function of glib-josn.
The problem is, that this function seems to skip arrays.
The array is not returned by "list_properties" function of the "ObjectClass" class. Furthermore the two
function store the properties without its name. The result actually looks like:
{
i : 1
}
I have tried to marshal the class myself, that's how I noticed arrays are not returned by "list_properties".
I tried to add support for array by using the "get_data" function of the "GLib.Object". This function doesn't
return data. Used it like this:
// build class and set values:
int j = testclass.get_data("i");
int j = testclass.get_data<int>("i");
I don't want to reimplement the array marshaling for every new class I build.
Is there any nice way to marshal array into json with a function that looks something like this:
array_to_data(Type baseType, array, [maybe add needed extraflags]);
or even integrate it into "Json.object_to_data()" and "Json.object_from_data()".
So long,
Johann
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]