public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { JToken value = null; var response = new FindConnectedObjectsResponse(); // status var json = JObject.ReadFrom(reader) as JObject; json.TryGetValue("status", out value); response.Status = serializer.Deserialize<Status>(value.CreateReader()); if (response.Status.IsSuccessful == false) return response; json.Remove("status"); // paging info // Extract paging info json.TryGetValue("paginginfo", out value); response.PagingInfo = serializer.Deserialize<PagingInfo>(value.CreateReader()); json.Remove("paginginfo"); // extract parent label json.TryGetValue("parent", out value); var parentLabel = value.ToString(); // Extract graph node. json.TryGetValue("nodes", out value); if (value.Type != JTokenType.Null) { var nodes = value.Values<JObject>(); ParseNodes(response, parentLabel, nodes, serializer); } else response.Nodes = new List<GraphNode>(); return response; }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { JToken value = null; var response = new FindConnectedObjectsResponse(); // status var json = JObject.ReadFrom(reader) as JObject; json.TryGetValue("status", out value); response.Status = serializer.Deserialize <Status>(value.CreateReader()); if (response.Status.IsSuccessful == false) { return(response); } json.Remove("status"); // paging info // Extract paging info json.TryGetValue("paginginfo", out value); response.PagingInfo = serializer.Deserialize <PagingInfo>(value.CreateReader()); json.Remove("paginginfo"); // extract parent label json.TryGetValue("parent", out value); var parentLabel = value.ToString(); // Extract graph node. json.TryGetValue("nodes", out value); if (value.Type != JTokenType.Null) { var nodes = value.Values <JObject>(); ParseNodes(response, parentLabel, nodes, serializer); } else { response.Nodes = new List <GraphNode>(); } return(response); }
private void ParseNodes(FindConnectedObjectsResponse response, string parentLabel, IEnumerable<JObject> nodes, JsonSerializer serializer) { response.Nodes = nodes.Select(x => ParseNode(parentLabel, x, serializer)).ToList(); }
private void ParseNodes(FindConnectedObjectsResponse response, string parentLabel, IEnumerable <JObject> nodes, JsonSerializer serializer) { response.Nodes = nodes.Select(x => ParseNode(parentLabel, x, serializer)).ToList(); }