Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can we have more Type Handler examples? #2

Open
Starpelly opened this issue Apr 13, 2024 · 3 comments
Open

Can we have more Type Handler examples? #2

Starpelly opened this issue Apr 13, 2024 · 3 comments

Comments

@Starpelly
Copy link

I've been trying to figure out how to serialize Guids but I cannot for the life of me figure out the serialization/deserialization API.
image

@EinScott
Copy link
Owner

I'm not sure yet how to document this in a better way wihtout it being huge, but in general the "defaulting" part of bon deserialize as far as type handlers are concerned is about making sure that container types (arrays, structs, ...) are defaulted "correctly", meaning that the rules "defaulting" follows are respected for the inner parts of the container (structs with fields marked as ignore, or private). Since you dont fully know what the container is holding. But here it's just primitives. Deserializing that always works simply. State.arrayKeepUnlessSet is unfortunate but exactly for passing the fact that someone placed the attribute on a field for the container type to the deserializer for that.

In your case, it's not a container type, you make it handle Guid like its internal array. So on deserialize (since you wouldn't be called if you weren't supposed to set the Guid) you can just call Value() directly again and provide the array. That should handle it just as expected (as long as the array is put back into the Guid afterward, or is a span).

If you're not doing something complicated Serialize and Deserialize will be fairly symmetrical. For more complex cases the existing list and dictionary type handlers are supposed to be references, but of course the actual implementation and exact use is not really given anywhere expect in the code itself right now. Maybe i'll add some thigns about the default functions specifically, the rest is probably more self expanatory?

Anyway, let me know if you run into more or if that works.

@Starpelly
Copy link
Author

I've decided to use strings instead like Newtonsoft.Json
This seems to work:
image

@EinScott
Copy link
Owner

Great, that works too of course

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants