You are not logged in.
Pages: 1
Hi!
Is that possible to serialize the given object a simple way (dump) just like RecordSaveJson?
The problem is that ObjectToJson always returns empty json if there is no properties! But I do not want any properties, I just have plain fields to serialize..
THe idea is that I want in some future switch from SuperObject to SynOpse for JSON serialization.
type
TMyClass = class
public
name: String;
value: Double;
end;
TMyRecord = record
public
name: String;
value: Double;
end;
Everything works fine with record, but never with a class.
SuperObject JSON or any other library does this without problem, but I cant get it working with SynCommons unit.
What do I miss?
1) I do not want or will descend from TSynPersistent;
2) I can't add properties/change the interfaces of the class;
3) I tried ObjectToVariant -> VariantToJson;
4) I have mORMot unit in uses list for TJSONSerializer.
Many thanks for your help!
Offline
We use the standard class RTTI, so we need to have published properties.
For what you expect, you would need to use the Delphi 2010+ RTTI. Since we want to stay compatible with Delphi 7/2007 and even more with FPC which lacks RTTI for non published properties, it is not possible in mORMot yet.
Note that you don't need to inherit from TSynPersistent: you can inherit from TPersistent or whatever class which has {$M+} markups to generate the RTTI for published properties.
Offline
Thanks for your answer!
Offline
Pages: 1