Customize how _type is handled
See original GitHub issueCurrently the _type
property always contains the assembly qualified name of the type. This means that if something changes between versions (e.g. an assembly or type is renamed), existing document can no longer be deserialized.
Is there a way to use custom type/name mappings instead? From what I see in the code, I don’t think so, but it would be a useful addition.
JSON.NET offers an extension point for this: the ISerializationBinder
interface, which lets you map a type to a name and vice versa. Is this something you’d consider adding to LiteDB? It would be very useful to make it easier to evolve apps with existing data.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Custom Type Handling - Dapper .NET
To map — or better — deserialize data coming from your database into a complex custom object Dapper supports a feature named “Custom...
Read more >How To Create Custom Types in TypeScript
This will allow you to create types that check specific string formats and add more customization to your TypeScript project.
Read more >Handling Custom Types - Polyfactory - Litestar
Sometimes you need to handle custom types, either from 3rd party libraries or from your own codebase. To achieve this, you can extend...
Read more >Can Eloquent handle custom types?
I'm working on building an API using Laravel 5 and Postgres for my database. Postgres allows for defining and using custom types. For...
Read more >events - How do I handle editing of custom types in a C# ...
It turns out I need to handle the CellParsing event: e.Value = new ExDateTime(e.Value.ToString()); e.ParsingApplied = true;.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I don’t think so, but it’s pretty simple. Just pass a
BsonMapper
with your custom type name binder to theLiteDatabase
ctor:I’m not sure it could help for this scenario…
That actually works. Implementing GetName the same as the default, and GetType returns the base class type on matching a condition. In my case I’m looking at the name containing certain words I know all my derived types have, which suits my needs. Anything else is null and reverts to throwing error.
Deserialise then returns instances of the base class, obviously ignoring properties from the derived. That’s okay for what I need.