public void GivenIHaveParsedAJSONObjectUsingTheseComponents() {
            var stream = new MemoryStream(Encoding.UTF8.GetBytes(Resources.JSONWithDuplicateObjects));
            var parser = new JsonObjectParser();

            var stopwatch = new Stopwatch();
            stopwatch.Start();

            Json.Parse(parser, stream, "item");

            stopwatch.Stop();
            _result1 = stopwatch.ElapsedMilliseconds;
        }
Example #2
0
        public void Counting_offer_5()
        {
            var bracket = new JsonObjectParser();

            bracket.Offer(Json);
            bracket.Poll();
            bracket.Poll();
            bracket.Poll();
            bracket.Poll();
            bracket.Poll();
            bracket.Poll();
            _bracketThroughputCounter.Increment();
        }
Example #3
0
        public void Collecting_json_buffer_when_valid_json_is_supplied_which_returns_none_until_valid_json_is_encountered()
        {
            var buffer = new JsonObjectParser();

            @"{ ""name"" : ""john""".ForEach(c =>
            {
                buffer.Offer(ByteString.FromString(c.ToString()));
                buffer.Poll().Should().Be(Option <ByteString> .None);
            });

            buffer.Offer(ByteString.FromString("}"));
            buffer.Poll().Value.ShouldAllBeEquivalentTo(ByteString.FromString(@"{ ""name"" : ""john""}"));
        }
        public void Can_Parse_Json_With_Arrays()
        {
            var     selector   = "channel.item[*].title";
            var     parser     = new JsonObjectParser();
            var     jsonString = parser.Parse(JSON_WITH_ARRAYS, selector);
            dynamic result     = JsonConvert.DeserializeObject <ExpandoObject>(jsonString);

            Assert.IsNotNull(result, "result was null");
            Assert.IsNotNull(result.title, "title was null");
            Assert.AreEqual(2, result.title.Count, "title length not correct.");
            Assert.AreEqual("Json.NET 1.3 + New license + Now on CodePlex", result.title[0], "first title is not correct.");
            Assert.AreEqual("LINQ to JSON beta", result.title[1], "second title is not correct.");
        }
Example #5
0
        public void Collecting_json_buffer_when_valid_json_is_supplied_which_has_one_object_should_successfully_parse_single_field_having_nested_object()
        {
            var          buffer  = new JsonObjectParser();
            const string content = "{ \"name\" : \"john\"," +
                                   "  \"age\"  : 101," +
                                   "  \"address\": {" +
                                   "       \"street\": \"Straight Street\"," +
                                   "       \"postcode\": 1234" +
                                   "  }" +
                                   "}";

            buffer.Offer(ByteString.FromString(content));
            buffer.Poll().Value.ToString().Should().Be(content);
        }
        public void GivenIHaveParsedAJSONObjectUsingTheseComponents()
        {
            var stream = new MemoryStream(Encoding.UTF8.GetBytes(Resources.JSONWithDuplicateObjects));
            var parser = new JsonObjectParser();

            var stopwatch = new Stopwatch();

            stopwatch.Start();

            Json.Parse(parser, stream, "item");

            stopwatch.Stop();
            _result1 = stopwatch.ElapsedMilliseconds;
        }
Example #7
0
        public void Collecting_json_buffer_when_valid_json_is_supplied_which_has_nested_array_should_successfully_parse()
        {
            var          buffer  = new JsonObjectParser();
            const string content = "{ \"name\" : \"john\"," +
                                   "  \"things\": [" +
                                   "      1," +
                                   "      \"hey\"," +
                                   "      3" +
                                   "      \"there\"" +
                                   "  ]" +
                                   "}";

            buffer.Offer(ByteString.FromString(content));
            buffer.Poll().Value.ToString().Should().Be(content);
        }
Example #8
0
        public void Collecting_json_buffer_when_valid_json_is_supplied_which_has_one_object_should_successfully_parse_single_field_having_string_value_containing_curly_brace_and_escape_character()
        {
            var buffer = new JsonObjectParser();

            buffer.Offer(ByteString.FromString("{ \"name\": \"john"));
            buffer.Offer(ByteString.FromString("\\\""));
            buffer.Offer(ByteString.FromString("{"));
            buffer.Offer(ByteString.FromString("}"));
            buffer.Offer(ByteString.FromString("\\\""));
            buffer.Offer(ByteString.FromString(" "));
            buffer.Offer(ByteString.FromString("hey"));
            buffer.Offer(ByteString.FromString("\""));
            buffer.Offer(ByteString.FromString("}"));
            buffer.Poll().Value.ToString().Should().Be("{ \"name\": \"john\\\"{}\\\" hey\"}");
        }
Example #9
0
 protected object ParseJsonObject()
 {
     try
     {
         JsonObjectParser objParser = new JsonObjectParser(jsonContent.Substring(currentPosition));
         object           result    = objParser.Parse();
         currentToken = jsonContent[currentPosition += objParser.currentPosition];
         MatchToken('}');
         return(result);
     }
     catch
     {
         throw;
     }
 }
        public void Can_Parse_Json_With_Nested_Array()
        {
            var     selector   = "channel.item[*].categories[*]";
            var     parser     = new JsonObjectParser();
            var     jsonString = parser.Parse(JSON_WITH_ARRAYS, selector);
            dynamic result     = JsonConvert.DeserializeObject <ExpandoObject>(jsonString);

            Assert.IsNotNull(result, "result was null");
            Assert.IsNotNull(result.categories, "categories array was null");
            Assert.AreEqual(4, result.categories.Count, "categories length not correct.");
            Assert.AreEqual("Json.NET", result.categories[0], "first categories is not correct.");
            Assert.AreEqual("CodePlex", result.categories[1], "second categories is not correct.");
            Assert.AreEqual("Json.NET", result.categories[2], "third categories is not correct.");
            Assert.AreEqual("LINQ", result.categories[3], "fourth categories is not correct.");
        }
        public void Can_Parse_Json_With_Arrays_And_Properties()
        {
            var     selector   = "channel.description,channel.link,channel.item[*].title";
            var     parser     = new JsonObjectParser();
            var     jsonString = parser.Parse(JSON_WITH_ARRAYS, selector);
            dynamic result     = JsonConvert.DeserializeObject <ExpandoObject>(jsonString);

            Assert.IsNotNull(result, "result was null");
            Assert.IsNotNull(result.description, "description was null");
            Assert.AreEqual("James Newton - King\'s blog.", result.description, "description is not correct.");
            Assert.IsNotNull(result.link, "link was null");
            Assert.AreEqual("http://james.newtonking.com", result.link, "link is not correct.");
            Assert.AreEqual(2, result.title.Count, "title length not correct.");
            Assert.AreEqual("Json.NET 1.3 + New license + Now on CodePlex", result.title[0], "first title is not correct.");
            Assert.AreEqual("LINQ to JSON beta", result.title[1], "second title is not correct.");
        }
Example #12
0
 private void AddSecret(VaultKeyValueSecret secret)
 {
     foreach (var pair in secret.Values)
     {
         if (pair.Value is JObject json)
         {
             var jsonData = new JsonObjectParser().Parse(json);
             foreach (var jsonPair in jsonData)
             {
                 var key = ConfigurationPath.Combine(secret.Key, pair.Key, jsonPair.Key);
                 Data.Add(key, jsonPair.Value);
             }
         }
         else
         {
             var key = ConfigurationPath.Combine(secret.Key, pair.Key);
             Data.Add(key, Convert.ToString(pair.Value));
         }
     }
 }
Example #13
0
        public bool syncCompany_ServerToLocal()
        {
            bool successProcess = true;
            // Realizar la peticiĆ³n http
            ServerConnectionService connection     = new ServerConnectionService();
            ServiceResponseResult   responseResult = connection.getCompaniesFromServer();

            successProcess = this.isValidResponse(responseResult);
            if (successProcess)
            {
                string result = responseResult.result.ToString();
                // Parsear el json de respuesta
                JsonObjectParser parser           = new JsonObjectParser((int)EntityType.Company);
                string           parsedJsonString = parser.parse(result);
                // Realizar la persistencia de los cambios
                CompanyRepository companyRepo = new CompanyRepository();
                companyRepo.saveList(JsonConvert.DeserializeObject <List <CPN_Company> >(parsedJsonString));
            }
            return(successProcess);
        }
Example #14
0
        public void Collecting_json_buffer_when_valid_json_is_supplied_which_has_multiple_objects_should_pops_the_right_object_as_buffer_is_filled()
        {
            var          buffer = new JsonObjectParser();
            const string input1 = @"{
                 ""name"": ""john"",
                 ""age"": 32
               }";
            const string input2 = @"{
                 ""name"": ""katie"",
                 ""age"": 25
               }";

            buffer.Offer(ByteString.FromString(input1 + "," + input2));
            buffer.Poll().Value.ToString().Should().Be(input1);
            buffer.Poll().Value.ToString().Should().Be(input2);

            buffer.Poll().Should().Be(Option <ByteString> .None);
            buffer.Offer(ByteString.FromString("{\"name\":\"jenkins\",\"age\": "));
            buffer.Poll().Should().Be(Option <ByteString> .None);

            buffer.Offer(ByteString.FromString("65 }"));
            buffer.Poll().Value.ToString().Should().Be("{\"name\":\"jenkins\",\"age\": 65 }");
        }
Example #15
0
        /// <summary>
        /// Parses the record field.
        /// </summary>
        /// <param name="field">The field.</param>
        /// <param name="parent">The parent schema.</param>
        /// <param name="namedSchemas">The named schemas.</param>
        /// <param name="position">The position.</param>
        /// <returns>
        /// Schema internal representation.
        /// </returns>
        /// <exception cref="System.Runtime.Serialization.SerializationException">Thrown when <paramref name="field"/> is not valid or when sort order is not valid.</exception>
        private RecordField ParseRecordField(JObject field, NamedSchema parent, Dictionary<string, NamedSchema> namedSchemas, int position)
        {
            var name = field.RequiredProperty<string>(Token.Name);
            var doc = field.OptionalProperty<string>(Token.Doc);
            var order = field.OptionalProperty<string>(Token.Order);
            var aliases = this.GetAliases(field, parent.FullName);
            var fieldType = field[Token.Type];
            if (fieldType == null)
            {
                throw new SerializationException(
                    string.Format(CultureInfo.InvariantCulture, "Record field schema '{0}' has no type.", field));
            }

            TypeSchema type = this.Parse(fieldType, parent, namedSchemas);
            object defaultValue = null;
            bool hasDefaultValue = field[Token.Default] != null;
            if (hasDefaultValue)
            {
                var objectParser = new JsonObjectParser();
                defaultValue = objectParser.Parse(type, field[Token.Default].ToString());
            }

            var orderValue = SortOrder.Ascending;
            if (!string.IsNullOrEmpty(order))
            {
                if (!SortValue.ContainsKey(order.ToUpperInvariant()))
                {
                    throw new SerializationException(
                        string.Format(CultureInfo.InvariantCulture, "Invalid sort order of the field '{0}'.", order));
                }
                orderValue = SortValue[order.ToUpperInvariant()];
            }

            var fieldName = new SchemaName(name);
            var attributes = new NamedEntityAttributes(fieldName, aliases, doc);

            return new RecordField(attributes, type, orderValue, hasDefaultValue, defaultValue, null, position);
        }