Open ionite34 opened 5 months ago
What, in your opinion, would be the expected result? As far as I can see, LiteDB serializes Enums as string and when you are trying to parse the string into an enum value, that doesnt exist, it fails.
What, in your opinion, would be the expected result? As far as I can see, LiteDB serializes Enums as string and when you are trying to parse the string into an enum value, that doesnt exist, it fails.
I agree the error by default seems to be standard since I think behavior in System.Text.Json is the same. I'm wondering if a config option for UnknownEnumAsDefault
like EnumAsInteger
for BsonMapper is available to deal with this globally? Or can I implement that myself with BsonMapper.Global.RegisterType
?
Version LiteDB version: 5.0.19 .NET: 8.0 OS: Occurs across our users in Win 11 / macOS / Linux
Describe the bug ArgumentException occurs when fetching litedb entries with properties of enums that have names that no longer exist or were changed. Is there a way for the bson deserializer to return 0 or some default enum value when this happens?
Code to Reproduce
var tempDir = Path.Combine(Path.GetTempPath(), "litedb-test-e31c667160d8"); Directory.CreateDirectory(tempDir);
using var db = new LiteDatabase(Path.Combine(tempDir, "test.db"));
var collection = db.GetCollection("Cat");
collection.Upsert(new Cat { Id = 100, Color = Color.Green });
public enum Color { Red = 0, Green = 1, Blue = 2 }
public class Cat { public int Id { get; set; } public Color Color { get; set; } }
Exception: