I have serialized xpo objects into JSON data in separate project using default session. But when I try to de-serialize the same within view controller i am getting default session error. I am able to get the current session but I am not sure how to deserialize by using the current session.
Newtonsoft is being used to serialize and deserialize.
string filetext= File.ReadAllText("importedfile.json");
Plugin pl = (Plugin)JsonConvert.DeserializeObject(filetext,jsonsettings);
Plugin is my class name to which the JSON data should get deserialized.
Presuming your
Plugintype inherits fromDevExpress.Xpo.XPObjectin the manner shown in the documentation example:And assuming that your deserialization code already has access to some
Session session, then define the followingCustomCreationConverter<Plugin>:And deserialize as follows:
When deserializing the type
Pluginthe converter'sCreate()method will be invoked to manufacture thePluginusing the provided session.If you are using multiple sessions, you will need to use a new
JsonSerializerSettingsfor each new session.This pattern can be used for any type inheriting from
XPObjectwith a public constructor taking aSessionobject.