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

Remove $type field #27

Closed
NVentimiglia opened this issue Mar 26, 2015 · 4 comments
Closed

Remove $type field #27

NVentimiglia opened this issue Mar 26, 2015 · 4 comments

Comments

@NVentimiglia
Copy link

I noticed that the serializer adds a $type field to serialized objects. What would the quickest way to remove the $type field ? Is this something I can handle in my interface class ?

@jacobdufault
Copy link
Owner

The $type field is emitted during serialization when there will not be enough context to fully recover the object graph during serialization (specifically, the type of object that the JSON maps back to).

If you remove $type, then deserialization will not work.

I'll look into adding a config to allow FS to act more like a JSON dumper, which sounds to be more like what you want (noticing some of the other issues you created).

@NVentimiglia
Copy link
Author

Gotcha. Is this an issue if I pass a specific type along with the json ?

See my API wrapper :
https://github.com/NVentimiglia/Unity3d-Databinding-Mvvm-Mvc/blob/master/Foundation%20Databinding/Assets/Plugins/JsonSerializer.cs

(Am I to understand that FS actually can detect my object? TIL, cool) ?

In my scenario I am communicating with a server side api. It fails if my json contains illegal properties ($Type). The ability to remove properties post-deserialization is good enough for me.

@jacobdufault
Copy link
Owner

I looked into adding a mode to prevent deserialization metadata from being added (like $type), but it mucks around with the logic a bit too much (and completely breaks serialization in certain scenarios, ie, when there is a cyclic object graph).

I've included a post-processor that removes the annotations in fsSerializer. Here is an example of how to use it:

void DoSerialize<T>(T obj) {
    fsData data;
    Serializer.Serialize(obj, out data).AssertSuccessWithoutWarnings();
    fsSerializer.StripDeserializationMetadata(ref data);
}

@NVentimiglia
Copy link
Author

I can work with that.

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