Breeze / breeze.server.net

Breeze support for .NET servers
MIT License
76 stars 62 forks source link

ContexProvider issues with arrays in saveMap #2

Closed guibulator closed 9 years ago

guibulator commented 10 years ago

There is in issue with arrays In the JsonToDictionary method of ContextProvider.cs. They are not taken into account.

For instances, I have a property which is a list of strings, when modifying it on the client and than saving it by calling saveChanges, The associated deserialized originalValuesMap's value is null.

Here is my fix:

private Dictionary<String, Object> JsonToDictionary(dynamic json) {
  if (json == null) return null;
  var jprops = ((System.Collections.IEnumerable)json).Cast<JProperty>();
  var dict = jprops.ToDictionary(jprop => jprop.Name, jprop => {
    var val = jprop.Value as JValue;
    if (val != null) {
      return val.Value;
    } 
    else if (jprop.Value as JArray != null){
        return jprop.Value as JArray;
    }
    else{
        return jprop.Value as JObject;
    }
  });
  return dict;
}

Thanks

steveschmitt commented 9 years ago

Thanks, guibulator, I put in your fix. Sorry it took so long.