-
Type:
Improvement
-
Resolution: Won't Do
-
Priority:
Minor - P4
-
None
-
Affects Version/s: 2.4.4
-
Component/s: Serialization
-
Environment:Win10 VisualStudio 2017
-
None
-
None
-
None
-
None
-
None
-
None
-
None
Having the following situation:
public class Article { [BsonId] [BsonRepresentation(BsonType.ObjectId)] public string Id { get; set; } [BsonExtraElements()] public Dictionary<string, Object> OtherData { get; set; } }
It appears the the [BsonExtraElements] tag prevents the driver from serializing complex types. An example would be the following class:
public class Bird { [BsonElement("_n")] [BsonRequired] public string Name { get; set; } [BsonElement("_s")] [BsonRequired] public string Species { get; set; } [BsonElement("_a")] [BsonRequired] public int Age { get; set; } }
With this tag placed on the dictionary, the driver fails to serialize an Article, if it's dictionary contains a Brid, for example. Is this intended behavior?
Without the tag it produces:
Unable to find source-code formatter for language: bson. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
{ "_id" : ObjectId("59b011975b8c05376c319f01"), "OtherData" : { "testBird" : { "_t" : "My.NameSpace.Bird", "_n" : "Jerry", "_s" : "European starling", "_a" : 4 } } }
I would assume it would be possible with the tag to serialize this as:
Unable to find source-code formatter for language: bson. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
{ "_id" : ObjectId("59b00cdd2b6e923b50fec052") "Bird" : { "_t" : "My.NameSpace.Bird" "_n" : "Jerry", "_s" : "European starling", "_a" : 4 } }
So that later this could be deserialized back into the 'OtherData' dictionary with the correct type. So the question I'd like to ask if I'm doing something wrong? Or is it a bug? Or is it intended behavior?
Greetings,