[QUESTION] v5 Example of how to use custom serializers?
See original GitHub issueHello, I’m a newbie to LiteDB and currently evaluating it for my purposes. I’ve tried to refer to the documentation, however it seems a lot of it is for v4 which is apparently out-of-date?
My question related to whether there is a concrete example of how to perform a customized de/serialization of any object.
My classes will be used by external developers, so I do not wish to decorate classes with LiteDB-specific tags.
As such, how would I go about persisting a class such as this:
public class Record
{
string Field1 {get; set;}
string Field2 {get; set;}
[NonSerialized]
string DontPersistField { get; set; }
}
Note that the class has no ‘Id’ field and I would like to omit ‘DontPersistField’ from being stored (it is marked as ‘NonSerialized’).
What is the correct way of persisting this in LiteDB without having to alter my class structure?
Thanks!
Issue Analytics
- State:
- Created 3 years ago
- Comments:5
Top Results From Across the Web
Custom serializers and deserializers in LiteDB v5.0.9
The release notes for LiteDB 5.0. 9 says, "Custom serializers and deserializers can now be used even with basic BSON types. This is...
Read more >Jackson - Custom Serializer
This article illustrated how to get to a custom JSON output with Jackson 2, by using Serializers. The implementation of all these examples...
Read more >The Serializer Component (Symfony Docs)
This article explains the philosophy of the Serializer and gets you familiar with the concepts of normalizers and encoders. The code examples assume...
Read more >How to use sessions
You can use the SESSION_SERIALIZER setting to customize the session serialization format. Even with the caveats described in Write your own serializer, ...
Read more >Working With JSON Data in Python
In this tutorial you'll learn how to read and write JSON-encoded data using Python. You'll see hands-on examples of working with Python's built-in...
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
@devmaestro1 If you want a solution that ignores fields with
NonSerializedAttribute
and works for any type, you could create a custom mapper class that inherits fromBsonMapper
and overridesGetTypeMembers
:LiteDB does not support these features currently, however they could be considered for the future.
You could achieve this with custom serializers and deserializers:
Thank you very much for your response on this. It has really helped me understand LiteDB a lot better.