Esempio n. 1
0
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            GetRecordsResponse response = new GetRecordsResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("Records", targetDepth))
                {
                    var unmarshaller = new ListUnmarshaller <Record, RecordUnmarshaller>(
                        RecordUnmarshaller.GetInstance());
                    response.Records = unmarshaller.Unmarshall(context);

                    continue;
                }

                if (context.TestExpression("NextShardIterator", targetDepth))
                {
                    response.NextShardIterator = StringUnmarshaller.GetInstance().Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
        private static void UnmarshallResult(JsonUnmarshallerContext context, GetRecordsResponse response)
        {
            int originalDepth = context.CurrentDepth;
            int targetDepth   = originalDepth + 1;

            while (context.Read())
            {
                if (context.TestExpression("Records", targetDepth))
                {
                    context.Read();
                    response.Records = new List <Record>();
                    RecordUnmarshaller unmarshaller = RecordUnmarshaller.GetInstance();
                    while (context.Read())
                    {
                        JsonToken token = context.CurrentTokenType;
                        if (token == JsonToken.ArrayStart)
                        {
                            continue;
                        }
                        if (token == JsonToken.ArrayEnd)
                        {
                            break;
                        }
                        response.Records.Add(unmarshaller.Unmarshall(context));
                    }
                    continue;
                }

                if (context.TestExpression("NextShardIterator", targetDepth))
                {
                    context.Read();
                    response.NextShardIterator = StringUnmarshaller.GetInstance().Unmarshall(context);
                    continue;
                }

                if (context.CurrentDepth <= originalDepth)
                {
                    return;
                }
            }

            return;
        }