Browse Source

Overwrite representation type.

pull/908/head 7.0.0-rc2
Sebastian 3 years ago
parent
commit
c7508e8f3a
  1. 1
      backend/src/Squidex.Domain.Apps.Entities.MongoDb/Text/MongoTextIndexEntity.cs
  2. 19
      backend/src/Squidex.Infrastructure.MongoDb/MongoDb/BsonJsonSerializer.cs
  3. 2
      backend/src/Squidex/appsettings.json
  4. 20
      backend/tests/Squidex.Infrastructure.Tests/MongoDb/BsonJsonSerializerTests.cs

1
backend/src/Squidex.Domain.Apps.Entities.MongoDb/Text/MongoTextIndexEntity.cs

@ -57,6 +57,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Text
[BsonIgnoreIfNull]
[BsonElement("go")]
[BsonJson]
[BsonRepresentation(BsonType.Document)]
public Geometry GeoObject { get; set; }
}
}

19
backend/src/Squidex.Infrastructure.MongoDb/MongoDb/BsonJsonSerializer.cs

@ -20,7 +20,22 @@ namespace Squidex.Infrastructure.MongoDb
public BsonType ActualRepresentation
{
get => Representation == BsonType.Undefined ? BsonJsonConvention.Representation : Representation;
get
{
var result = Representation;
if (result == BsonType.Undefined)
{
result = BsonJsonConvention.Representation;
}
if (result == BsonType.Undefined)
{
result = BsonType.Document;
}
return result;
}
}
public JsonSerializerOptions Options
@ -35,7 +50,7 @@ namespace Squidex.Infrastructure.MongoDb
public BsonJsonSerializer(BsonType representation)
{
if (representation is not BsonType.Undefined and not BsonType.String and not BsonType.Binary)
if (representation is not BsonType.Undefined and not BsonType.String and not BsonType.Binary and not BsonType.Document)
{
throw new ArgumentException("Unsupported representation.", nameof(representation));
}

2
backend/src/Squidex/appsettings.json

@ -487,7 +487,7 @@
// Defines how key-value-store values are represented in MongoDB (e.g. app, rule, schema).
//
// SUPPORTED: Undefined (Objects), String, Binary (from slow to fast).
// SUPPORTED: Document, String, Binary (from slow to fast).
"valueRepresentation": "Undefined",
"atlas": {

20
backend/tests/Squidex.Infrastructure.Tests/MongoDb/BsonJsonSerializerTests.cs

@ -21,6 +21,13 @@ namespace Squidex.Infrastructure.MongoDb
public T Value { get; set; }
}
public class TestWrapperDocument<T>
{
[BsonJson]
[BsonRepresentation(BsonType.Document)]
public T Value { get; set; }
}
public class TestWrapperString<T>
{
[BsonJson]
@ -124,6 +131,19 @@ namespace Squidex.Infrastructure.MongoDb
deserialized.Should().BeEquivalentTo(source);
}
[Fact]
public void Should_serialize_and_deserialize_as_document()
{
var source = new TestWrapperDocument<TestObject>
{
Value = TestObject.CreateWithValues()
};
var deserialized = source.SerializeAndDeserializeBson();
deserialized.Should().BeEquivalentTo(source);
}
[Fact]
public void Should_serialize_and_deserialize_as_string()
{

Loading…
Cancel
Save