Page 1 of 1

using group widget with json instead of xml

PostPosted: Sun Oct 14, 2012 3:58 pm
by whiteatom
Hi there.. new to xataface and I am so far... impressed. I would like to adjust one thing though. I use a fair bit of JSON encoded fields to store meta data and it would be very helpful if I could get xataface to read and write JSON data behind the group widget instead of xml. Is there a pluggable system for parsers? is there anyway I could customize this without tearing the entire app apart?

Re: using group widget with json instead of xml

PostPosted: Tue Oct 16, 2012 7:07 am
by shannah
Yes you can implement your own serializer for that field by implementing the fieldname__serialize() method in the delegate class. I'm going to need to look through my notes to find an example of this method for you. ... will post soon

Re: using group widget with json instead of xml

PostPosted: Sun Oct 21, 2012 3:57 pm
by whiteatom
That would be wicked :) when ever you get a chance.. the docs are pretty poor for that kind of stuff.

Re: using group widget with json instead of xml

PostPosted: Fri Oct 26, 2012 8:33 am
by shannah
You can implement fieldname__parse() and fieldname__serialize() methods to override the serialization and loading of fields in your database. E.g.
Code: Select all
function myfield__parse($data){
    if ( is_string($data) ){
        return json_decode($data, false);
    }
    return $data;
}

function myfield__serialize($data){
    return json_encode($data);
}


Haven't tested this particular code, but should work.

You may want to check out
http://weblite.ca/svn/dataface/core/tru ... Record.php (the setValue() method is it asks the table to parse input).
http://weblite.ca/svn/dataface/core/tru ... /Table.php (the parse() method...)
http://weblite.ca/svn/dataface/core/tru ... alizer.php (actually does the serialization).

Implementing xxx__parse() and xxx__serialize() overrides the default mechanisms.