question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support defining the serializer and BSON representation for a property

See original GitHub issue

<small>Issue converted to Proposal by @Turnerj 2023-06-04</small>

Proposal

Allow finer control of the serialization system for MongoDB through MongoFramework. Currently you can not control the BSON Representation (eg. C# string can’t be represented as BSON ObjectId) however doing so allows greater compatibility in a number of scenarios.

This could be accomplished well with support for defining the serializer per-property in MongoFramework. With the appropriate extension methods during the builder process, you could then control the representation that would be used. This first-party support would then unlock the ability to do the same attribute-level control of serializer (and optionally representation).

Original Issue

It does not allow me to read the entities of a mongo database due to this problem.

image image

Issue Analytics

  • State:open
  • Created 4 months ago
  • Comments:15 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
CristianBonillacommented, Jun 4, 2023

It would be nice to support it in a future version or find a way to support it in older versions too.

1reaction
Turnerjcommented, Jun 4, 2023

Yes, mostly. Like I think being able to define what a particular property should be represented as is quite useful but I need to look at the bigger picture of how I’d integrate it with MongoFramework.

Right now the very high level design I’m thinking is with MongoFramework’s internal mapping system, track the serializer used for a particular property - basically allow you to set IBsonSerializer. From there, I could just add some extension methods to my builder system to allow reconfiguring an existing serializer to change representation.

The big bit with this piece of work is that it makes MongoFramework responsible about what serializer is used for what property. By that I mean, MongoFramework will be determining the default serializer for each type rather than the driver by default. This is probably a good thing to do long term anyway (gives more flexibility in mapping) but given the wide variety of types that people could use, it becomes complicated ensuring backwards compatibility.

The end result then for consumers of MongoFramework would be both a similar attribute like the driver has to define the representation and also have first-party support in the fluent builder system.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Serialization Tutorial
A class map is a structure that defines the mapping between a class and a BSON document. It contains a list of the...
Read more >
BsonSerializationException when serializing a Dictionary ...
Bson.BsonSerializationException: When using DictionaryRepresentation.Document key values must serialize as strings. Here's a minimal reproduce:
Read more >
JSON And BSON
Learn how MongoDB uses the lightweight and flexible BSON, an extension JSON, ... are some example JSON objects and their corresponding BSON representations....
Read more >
Migrate from Newtonsoft.Json to System.Text.Json - .NET
Json can serialize and deserialize fields as well as properties. In System.Text.Json, use the JsonSerializerOptions.IncludeFields global setting ...
Read more >
Spring Data MongoDB - Reference Documentation
The method parser supports setting an IgnoreCase flag for individual properties (for example, findByLastnameIgnoreCase(…) ) or for all properties of a type that ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found