diff --git a/Tests/YDotNet.Tests.Unit/Extensions/Conversion.cs b/Tests/YDotNet.Tests.Unit/Extensions/Conversion.cs index 26230b89..d10b2e41 100644 --- a/Tests/YDotNet.Tests.Unit/Extensions/Conversion.cs +++ b/Tests/YDotNet.Tests.Unit/Extensions/Conversion.cs @@ -42,6 +42,34 @@ public void ConvertTo() Assert.That(result.Value, Is.EqualTo("Hello YDotNet")); } + [Test] + public void CanParseMapsToObject() + { + // Arrange + var doc = new Doc(); + var items = doc.Array("items"); + + using (var transaction = doc.WriteTransaction()) + { + var map = Input.Map(new Dictionary() + { + ["value"] = Input.String("Hello YDotNet"), + }); + items.InsertRange(transaction, 0, map); + } + + using (var transaction = doc.ReadTransaction()) + { + var map = items.Get(transaction, 0); + + // Act + var parsed = map.To(transaction); + + // Assert + Assert.That(parsed.Value, Is.EqualTo("Hello YDotNet")); + } + } + [Test] public void ConvertToJson() { diff --git a/YDotNet.Extensions/YDotNetExtensions.cs b/YDotNet.Extensions/YDotNetExtensions.cs index dd6ac49e..1f98772b 100644 --- a/YDotNet.Extensions/YDotNetExtensions.cs +++ b/YDotNet.Extensions/YDotNetExtensions.cs @@ -91,14 +91,14 @@ static void WriteCollection(JsonArray array, Utf8JsonWriter jsonWriter, Transact static void WriteMap(Map map, Utf8JsonWriter jsonWriter, Transaction transaction) { - jsonWriter.WriteStartArray(); + jsonWriter.WriteStartObject(); foreach (var property in map.Iterate(transaction)) { WriteProperty(property.Key, property.Value, jsonWriter, transaction); } - jsonWriter.WriteEndArray(); + jsonWriter.WriteEndObject(); } static void WriteArray(Array array, Utf8JsonWriter jsonWriter, Transaction transaction)