Hi,
I'm using Mootools classes extensively in my business logic. I would
like to encode only the "options" of corresponding instances in JSON.
Automatically.
Let me take an example. Encoding an instance of the following class:
########
var Activity = new Class({
Implements: [Options],
initialize: function(options) {
this.options = options;
},
options: { // Defaults
"vehicles": []
},
getId: function() {
return this.options.id;
},
getStartDateTime: function() {
return this.options.startDateTime;
},
getEndDateTime: function() {
return this.options.endDateTime;
},
getOriginStation: function() {
return this.options.originStation;
},
getDestinationStation: function() {
return this.options.destinationStation;
},
getComment: function() {
return this.options.comment;
},
getVehicles: function() {
return this.options.vehicles;
}
});
########
Now, calling "JSON.encode(myActivity)" will result in the following
JSON:
########
{
"options":{
"startDateTime":"2011-11-11T05:12:22.850Z",
"endDateTime":"2011-11-11T05:27:22.850Z",
"originStation":{
"$caller":null,
"caller":null,
"options":{
"code":"CST",
"name":"Stockholm C"
}
},
"destinationStation":{
"$caller":null,
"caller":null,
"options":{
"code":"CST",
"name":"Stockholm C"
}
},
"vehicles":[
{
"$caller":null,
"caller":null,
"options":{
"id":"2110",
"type":"RABe525"
}
}
],
"trainNumber":"8424",
"tractionType":"M1"
},
"$caller":null,
"caller":null
}
########
But I would like only the "options" to be encoded, which would result
in the following JSON:
########
{
"startDateTime":"2011-11-11T05:12:22.850Z",
"endDateTime":"2011-11-11T05:27:22.850Z",
"originStation":{
"code":"CST",
"name":"Stockholm C"
},
"destinationStation":{
"code":"CST",
"name":"Stockholm C"
},
"vehicles":[
{
"id":"2110",
"type":"RABe525"
}
],
"trainNumber":"8424",
"tractionType":"M1"
}
########
Is there a way to do this automatically?