WriteEnd() public method

Writes the end of the current JSON object or array.
public WriteEnd ( ) : void
return void
Exemplo n.º 1
0
        void ParseGroup(TextGroupDefinition group)
        {
            _writer.WritePropertyName(group.Name);
            if (!group.RecordBreakOnLine)
            {
                _writer.WriteStartObject();
            }
            else
            {
                _writer.WriteStartArray();
            }
            int lineNo = 0;

            while (!_reader.EndOfStream)
            {
                if (_line == null || lineNo > 0)
                {
                    _line = _reader.ReadLine();
                }
                lineNo++;
                if (_line.Trim() != string.Empty && lineNo >= group.ElementsStartOnLine)
                {
                    if (group.EndString != null && _line.Contains(group.EndString))
                    {
                        break;
                    }
                    if (group.RecordBreakOnLine)
                    {
                        _writer.WriteStartObject();
                    }

                    foreach (var subGroup in group.Groups)
                    {
                        if (_line.Contains(subGroup.StartString))
                        {
                            ParseGroup(subGroup);
                        }
                    }

                    foreach (var element in group.Elements)
                    {
                        ParseElement(element, lineNo);
                    }
                    if (group.RecordBreakOnLine)
                    {
                        _writer.WriteEnd();
                    }
                }
            }
            _writer.WriteEnd();              // object or array
        }
Exemplo n.º 2
0
 public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
 {
     writer.Formatting = Newtonsoft.Json.Formatting.Indented;
     writer.WritePropertyName("ObjectId");
     writer.WriteValue(((ObjectId) value).ToString());
     writer.WriteEnd();
 }
Exemplo n.º 3
0
 public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
 {
     var la = (IGroup)value;
     writer.WriteStartObject();
     writer.WritePropertyName("name");
     writer.WriteValue(la.Name);
     writer.WritePropertyName("lights");
     serializer.Serialize(writer, la.Lights);
     writer.WriteEnd();
 }
Exemplo n.º 4
0
        internal void WriteProperties(JsonWriter jsonWriter)
        {
            var properties = this._type.GetProperties();
            foreach (var p in properties)
            {
                var att = ElasticAttributes.Property(p);
                if (att != null && att.OptOut)
                    continue;

                var propertyName = this.Infer.PropertyName(p);
                var type = GetElasticSearchType(att, p);

                if (type == null) //could not get type from attribute or infer from CLR type.
                    continue;

                jsonWriter.WritePropertyName(propertyName);
                jsonWriter.WriteStartObject();
                {
                    if (att == null) //properties that follow can not be inferred from the CLR.
                    {
                        jsonWriter.WritePropertyName("type");
                        jsonWriter.WriteValue(type);
                        //jsonWriter.WriteEnd();
                    }
                    if (att != null)
                        this.WritePropertiesFromAttribute(jsonWriter, att, propertyName, type);
                    if (type == "object" || type == "nested")
                    {

                        var deepType = p.PropertyType;
                        var deepTypeName = this.Infer.TypeName(deepType);
                        var seenTypes = new ConcurrentDictionary<Type, int>(this.SeenTypes);
                        seenTypes.AddOrUpdate(deepType, 0, (t, i) => ++i);

                        var newTypeMappingWriter = new TypeMappingWriter(deepType, deepTypeName, this._connectionSettings, MaxRecursion, seenTypes);
                        var nestedProperties = newTypeMappingWriter.MapPropertiesFromAttributes();

                        jsonWriter.WritePropertyName("properties");
                        nestedProperties.WriteTo(jsonWriter);
                    }
                }
                jsonWriter.WriteEnd();
            }
        }
Exemplo n.º 5
0
 private void HandleError(JsonWriter writer, int initialDepth)
 {
   this.ClearErrorContext();
   if (writer.WriteState == WriteState.Property)
     writer.WriteNull();
   while (writer.Top > initialDepth)
     writer.WriteEnd();
 }
Exemplo n.º 6
0
		public void Indenting()
		{
			StringBuilder sb = new StringBuilder();
			StringWriter sw = new StringWriter(sb);

			using (JsonWriter jsonWriter = new JsonWriter(sw))
			{
				jsonWriter.Formatting = Formatting.Indented;

				jsonWriter.WriteStartObject();
				jsonWriter.WritePropertyName("CPU");
				jsonWriter.WriteValue("Intel");
				jsonWriter.WritePropertyName("PSU");
				jsonWriter.WriteValue("500W");
				jsonWriter.WritePropertyName("Drives");
				jsonWriter.WriteStartArray();
				jsonWriter.WriteValue("DVD read/writer");
				jsonWriter.WriteComment("(broken)");
				jsonWriter.WriteValue("500 gigabyte hard drive");
				jsonWriter.WriteValue("200 gigabype hard drive");
				jsonWriter.WriteEnd();
				jsonWriter.WriteEndObject();
			}

			string expected = @"{
  ""CPU"": ""Intel"",
  ""PSU"": ""500W"",
  ""Drives"": [
    ""DVD read/writer""
    /*(broken)*/,
    ""500 gigabyte hard drive"",
    ""200 gigabype hard drive""
  ]
}";
			string result = sb.ToString();

			Console.WriteLine("Indenting");
			Console.WriteLine(result);

			Assert.AreEqual(expected, result);
		}
Exemplo n.º 7
0
		public void State()
		{
			StringBuilder sb = new StringBuilder();
			StringWriter sw = new StringWriter(sb);

			using (JsonWriter jsonWriter = new JsonWriter(sw))
			{
				Assert.AreEqual(WriteState.Start, jsonWriter.WriteState);

				jsonWriter.WriteStartObject();
				Assert.AreEqual(WriteState.Object, jsonWriter.WriteState);
				
				jsonWriter.WritePropertyName("CPU");
				Assert.AreEqual(WriteState.Property, jsonWriter.WriteState);

				jsonWriter.WriteValue("Intel");
				Assert.AreEqual(WriteState.Object, jsonWriter.WriteState);

				jsonWriter.WritePropertyName("Drives");
				Assert.AreEqual(WriteState.Property, jsonWriter.WriteState);

				jsonWriter.WriteStartArray();
				Assert.AreEqual(WriteState.Array, jsonWriter.WriteState);

				jsonWriter.WriteValue("DVD read/writer");
				Assert.AreEqual(WriteState.Array, jsonWriter.WriteState);

				jsonWriter.WriteEnd();
				Assert.AreEqual(WriteState.Object, jsonWriter.WriteState);

				jsonWriter.WriteEndObject();
				Assert.AreEqual(WriteState.Start, jsonWriter.WriteState);
			}
		}
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var document = value as DocumentRevision;
            writer.WriteStartObject();

            if (!string.IsNullOrEmpty(document.docId))
            {
                writer.WritePropertyName("_id");
                serializer.Serialize(writer, document.docId);
            }

            if (!string.IsNullOrEmpty(document.revId))
            {
                writer.WritePropertyName("_rev");
                serializer.Serialize(writer, document.revId);
            }
            if (document.isDeleted)
            {
                writer.WritePropertyName("_deleted");
                serializer.Serialize(writer, document.isDeleted);
            }

            foreach (var pair in document.body)
            {
                writer.WritePropertyName(pair.Key);
                serializer.Serialize(writer, pair.Value);
            }

            writer.WriteEnd();
        }