Can't deserialize JSON.
Created at 01 Nov 2016, 22:59
Can't deserialize JSON.
01 Nov 2016, 22:59
Hello.
I had serialized data of position in JSON, but can't deserialize it back.
This line
Position pos = JsonConvert.DeserializeObject<Position>(responseData);
return error "Could not create an instance of type cAlgo.API.Position. Type is an interface or abstract class and cannot be instantiated. Path 'SymbolCode', line 2, position 15."
That I do wrong ?
Thanks.
firemyst
30 Dec 2023, 10:07 ( Updated at: 31 Dec 2023, 16:08 )
You're doing nothing wrong. “Position” is defined as an abstract interface in cAlgo:
https://help.ctrader.com/ctrader-automate/references/Trading/Positions/Position/
In the process of Deserialization, it involves creating an instance, and you can't create instances of interfaces.
Here's a blog article with a long way around the issue if you really need to do that:
https://dotnetfalcon.com/deserialize-into-interface/
@firemyst