-
Notifications
You must be signed in to change notification settings - Fork 33
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
Deserialize H5 Newtownsoft Json to deserialize a derived type class? #80
Comments
I afraid no, H5 version is very limited. The single option is to use implicit cast operator. If it is OK for you to pass data as string and restore object from string using cast operator. |
You can store the type info in the json using a custom JsonSerializerSettings: var jsonSettings = new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.Objects,
SerializationBinder = AssemblyNameIgnoringSerializationBinder.Instance
};
var json = JsonConvert.SerializeObject(derivedObject, jsonSettings);
var deserialized = JsonConvert.DeserializeObject<BaseType>(json, jsonSettings); |
Hmm, I never seen this option before. For example Though as I see you cannot decide inside binder which Type to provide depending on data (only on type name): public interface ISerializationBinder
{
Type BindToType(string assemblyName, string typeName);
void BindToName(Type serializedType, out string assemblyName, out string typeName);
} Probably it is possible to provide different binders depending on manually extracted data. Is it the idea? |
Is there any way to use H5 Newtownsoft Json to deserialize a derived type class?
Store the class type as a json-property and do a custom deserialize and check the property to create instance of correct type class?
Any ideas?
The text was updated successfully, but these errors were encountered: