Advertisement
dualarrow

Custom Serializer Problem

Nov 12th, 2020
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. I'm trying to get a custom serializer to serialize a custom class in a custom class but I keep getting stuck on the SerrializeAttribute method. The SerializeRoot gets called 1st, and I have it calling the SerializeAttribute once for each property of my other custom classes. What I think I'm missing is a means to call a method that can will continue the serialization without me having to serialize from my root object all the way up manuallybut I cant see how to do that.
  2.  
  3. Does anyone have an example of a custom serializer that can serialize 2 classes like the following
  4.  
  5. TClass2 = class
  6. private
  7. FString;
  8. public
  9. property Data: string read FString write FString;
  10. end;
  11.  
  12. TClass1 = class
  13. private
  14. FOtherClass: TClass2;
  15. public
  16. property OtherClass: TClass2 read FOtherClass;
  17. end;
  18.  
  19. I can code the serializer for TClass1, but what should the serializer of TClass1 do when it tries to serialize its member OtherClass ?
  20.  
  21. I'm thinking that TClass1 serializer is only meant to concern itself with itself and not TClass2. It would probably do somethiong like
  22.  
  23. aSerializerObject := TJDOJSONObject.Create;
  24. (aSerializerObject as TJDOJSONObject).O['OtherClass'];
  25.  
  26. which defines the property as null and returns and that the serializing engine can continue it's process but I havent been able to figure out how.
  27.  
  28. In the pastebin sample, my problem is in TTestRecordSerializer.SerializeRoot there I call the attibute serializer which I'm sure is coded wrong.
  29.  
  30. Sorry about this long post, but it's difficult to explain and I doubt I have explained it enough.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement