You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have the following custom mappers, where the type of WorldItem.Position is a Vector3. When deserializing WorldItem, the Vector3 type is not deserialized to the type and is instead a BsonValue. How do I embed custom types?
BsonMapper.Global.RegisterType<WorldItem>(
serialize: w =>
{
var doc = new BsonDocument
{
["position"] = new BsonValue(w.Position),
["rotation"] = new BsonValue(w.Rotation)
};
return doc;
},
deserialize: doc => new WorldItem(doc["_id"], doc["position"], doc["rotation"])
);
BsonMapper.Global.RegisterType(
serialize: v => new BsonArray(v.X, v.Y, v.Z),
deserialize: b => new Vector3(b[0].AsDouble, b[1].AsDouble, b[2].AsDouble)
);
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have the following custom mappers, where the type of
WorldItem.Positionis aVector3. When deserializing WorldItem, theVector3type is not deserialized to the type and is instead a BsonValue. How do I embed custom types?Beta Was this translation helpful? Give feedback.
All reactions