Browse Source

Json Writer fixed

pull/195/head
Sebastian Stehle 8 years ago
parent
commit
f96529dcf0
  1. 5
      src/Squidex.Infrastructure.MongoDb/MongoDb/BsonJsonWriter.cs
  2. 38
      tests/Squidex.Infrastructure.Tests/MongoDb/BsonConverterTests.cs

5
src/Squidex.Infrastructure.MongoDb/MongoDb/BsonJsonWriter.cs

@ -23,6 +23,11 @@ namespace Squidex.Infrastructure.MongoDb
this.bsonWriter = bsonWriter; this.bsonWriter = bsonWriter;
} }
public override void WritePropertyName(string name)
{
bsonWriter.WriteName(name.EscapeJson());
}
public override void WritePropertyName(string name, bool escape) public override void WritePropertyName(string name, bool escape)
{ {
bsonWriter.WriteName(name.EscapeJson()); bsonWriter.WriteName(name.EscapeJson());

38
tests/Squidex.Infrastructure.Tests/MongoDb/BsonConverterTests.cs

@ -126,6 +126,44 @@ namespace Squidex.Infrastructure.MongoDb
target.ShouldBeEquivalentTo(source); target.ShouldBeEquivalentTo(source);
} }
[Fact]
public void Should_write_problematic_object()
{
var buggy = new
{
a = new
{
iv = 1
},
b = new
{
iv = JObject.FromObject(new
{
lat = 1.0,
lon = 3.0
})
}
};
var stream = new MemoryStream();
using (var writer = new BsonJsonWriter(new BsonBinaryWriter(stream)))
{
serializer.Serialize(writer, buggy);
writer.Flush();
}
stream.Position = 0;
using (var reader = new BsonJsonReader(new BsonBinaryReader(stream)))
{
var target = serializer.Deserialize(reader, buggy.GetType());
target.ShouldBeEquivalentTo(buggy);
}
}
[Fact] [Fact]
public void Should_serialize_with_reader_and_writer() public void Should_serialize_with_reader_and_writer()
{ {

Loading…
Cancel
Save