Serialisation of complex JSON objects

Jan 6, 2012 at 6:39 AM

Hi there,

Just wondering if anyone has any idea what's going on here - I'm trying to call a method in the controller from a widget with the following:

this.options.sendRequest({
                url
: this.options.dataUrl,
                data
: queueNotificationData,
                cache
: false,
                dataType
: 'json',
                success
: function (data) {
                    that
.data = data;
                    that
._showSavedMessage();
               
},
                error
: function () {
                    that
._showErrorMessage();
               
}
           
});

queueNotificationData is basically a bunch of form values +
AffectedCustomerVOs: that.customerVOs 

which is a collection that was retrieved during an earlier call and passed from widget to widget as an option.
The data in that.customerVOs appears to be intact and fine - alerts prior to this call show the fields have values
and everything looks good.

The controller method looks like:
[HttpPost]
   
[Authorize]
   
[ValidateInput(false)]
   
public JsonResult QueueNotificationBatch(QueueNotificationInputModel param)
   
{
         
//do some work - code not included
   
}
and
QueueNotificationInputModel is defined as shown:

public class QueueNotificationInputModel
{
   
public string BatchServiceIds { get; set; }
   
public List<CustomerVO> AffectedCustomerVOs { get; set; }
   
public string StartDate { get; set; }
   
public string StartTime { get; set; }
   
public string EndDate { get; set; }
   
public string EndTime { get; set; }
   
public string ETR { get; set; }
   
public string PTW { get; set; }
   
public string SelectedTemplate { get; set; }
   
public string IncidentFlag { get; set; }
   
public string IncidentNumber { get; set; }
   
public bool SendToSubscriber { get; set; }
   
public bool SendToCustomer { get; set; }
   
public bool SendToSMC { get; set; }
   
public string DescriptionOfWorks { get; set; }

   
public QueueNotificationInputModel()
   
{
       
AffectedCustomerVOs = new List<CustomerVO>();
   
}
}

The majority of the code works fine - the method in the controller gets called and the fields are mostly fine. The exception is
the AffectedCustomerVOs field which has odd behaviour - the list has several items in it which is correct but the fields within
each CustomerVO (email, name etc.) are all null despite it clearly being there on the JSON side - what's going on here? some
sort of serialisation problem I think? is it better to pass the customer list through as a raw JSON string and deal with it on
the c# side? I'm confused as to why the customerVO list clearly has the correct number of items but the data is lost...

Jan 6, 2012 at 12:45 PM

Sorry - found the problem... needed to JSON.Stringify the object before sending it through. Not entirely sure why it worked in another widget with a similar object as a parameter - perhaps as this one had an array/list whereas the other only had one-to-one relationships

Developer
Jan 6, 2012 at 4:11 PM

Hi,

I'm glad you have found a solution to your problem. Thanks for sharing this with the rest of the community as it might be useful for other users that could be facing a similar issue.

Thanks,

Damian Cherubini
http://blogs.southworks.net/dcherubini