C
C#2y ago
abcyz

I need to serialize a bunch of non-primitive types. How would I do this?

I'm using JsonSerializer.serializeToUtf8Bytes I need to serialize a class that contains a bitmap, and some custom classes with properties
7 Replies
abcyz
abcyz2y ago
Basically I need to serialize the Bitmap and the properties of the other classes
Doombox
Doombox2y ago
depending on your usecase you could serialize the raw bitmap data as base64 perhaps
abcyz
abcyz2y ago
I'm using avalonia ui right now. But the thing is I've used Unity a few times, and I woud just apply the ISerializable interface and instruct how to serialize and deserialize. Cant i do that with jsonserializer? I dont remember if the ISerializable was part or not of the unity ecossystem actually...
Doombox
Doombox2y ago
depends which you're using, most offer the ability to provide custom serialisers for specific types
SUPER MEGA T REX
How to write custom converters for JSON serialization - .NET
Learn how to create custom converters for the JSON serialization classes that are provided in the System.Text.Json namespace.
Doombox
Doombox2y ago
should be a simple case of writing a converter for bitmap which converts to/from base64 or raw bytes, whatever you fancy
abcyz
abcyz2y ago
Thanks, i also have an enumerable of an interface that have other types to, idk how to do this