Answer the question
In order to leave comments, you need to log in
Deserializing an abstract class?
Greetings.
There is a set of Delphi XE2 classes:
TBaseAbstractClass = class abstract
name : string;
end;
TDerivedClassStr = class(TBaseAbstractClass)
value : string;
end;
TDerivedClassFloat = class(TBaseAbstractClass)
value : float;
end;
TMyObject = class
objs : array of TBaseAbstractClass;
end;
{
[
{"name" : "name1", "value" : "value1"},
{"name" : "name1", "value" : "value2"}
]
}
TMyObject = class
objs : array of TDerivedClassStr;
end;
Answer the question
In order to leave comments, you need to log in
Didn't use superobject, but how does he guess what type of class needs to be deserialized? It's not obvious from your JSON. You need to store the class name in an array when serializing and when deserializing create them using RTTI.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question