I try not to delete the deserialization of the circular graph of objects,
Json.net works well when serializing circular references: adding $ id to objects and replacing objects with $ ref = * objectId. When I send the same data back to the MVC action, it will not deserialize correctly - replacing $ refs with empty objects.
I use json.net for serialization and deserialization, deserialization is implemented in a custom IValueProvider - https://json.codeplex.com/discussions/347099
I noticed that when deserializing an anonymous object
JsonConverter.Deserialize(json);
he will not engage in circular links. but when deserializing using a generic type
JsonConverter.Deserialize<EntityType>(json)
it will deserialize correctly.
But I can not find the type in GetValueProvider (ControllerContext controllerContext)
any help would be appreciated
Edit- In my current fix, I pass all json as a string and use
JsonConverter.Deserialize<EntityType>(json)
with the right type in the controller action, but this is definitely not the right way to work with json + mvc4 ... I need a better way to integrate it into mvc, started the generosity
Edit - More Code Type:
[JsonObject(IsReference = true)] public class DynamicEntity : EntityWithID<Guid> { .... public virtual IList<DynamicEntity> ReferenceFields { get; set; } }
json to deserialize is the output of the Serialize method for Json.net.
{"$id":"1","ReferenceFields":[{"$ref":"1"}],"Id":"9f9de7f3-865e-4511-aeac-a2ff01193b06"}
The problem is integration with MVC, as json goes back and forth between the server and the client. I already have js methods to change it back and forth in the same exact format - it is checked how I use it now:
public ActionResult EntitySaveOrUpdate(string entity) { var entityToSave = JsonConvert.DeserializeObject<DynamicEntity>(entity); ... }
And it works fine, but I need better integration with MVC, not deserialization in all of my actions ...