mvanrijnen 130 Posted August 26 Anoyone an idea how to get this done? If i have a record/class as a return type for q request, i sometimes want to hide certain properties for the (de)serialization process. can not find what to use with the MARS framework for this? Share this post Link to post
Andrea Magni 77 Posted 22 hours ago Hi @mvanrijnen, there is a JSONNameAttribute you can use to tweak serialization (and deserialization). Just decorate your field with JSONName('') to skip serialization/deserialization. If you need some logic, you can add a special method to your record type and it will be fired by the serialization/deserialization mechanism. The method should match this signature: TMyRecord.ToJSONFilter(const AMember: TRttiMember; const AObj: TJSONObject): Boolean; Just return False and implement your logic in the ToJSONFilter method. It is then up to you to add or not the value of AMember to the AObj that is being serialized. Sincerely, Andrea 1 Share this post Link to post
mvanrijnen 130 Posted 20 hours ago (edited) 1 hour ago, Andrea Magni said: Hi @mvanrijnen, there is a JSONNameAttribute you can use to tweak serialization (and deserialization). Just decorate your field with JSONName('') to skip serialization/deserialization. If you need some logic, you can add a special method to your record type and it will be fired by the serialization/deserialization mechanism. The method should match this signature: TMyRecord.ToJSONFilter(const AMember: TRttiMember; const AObj: TJSONObject): Boolean; Just return False and implement your logic in the ToJSONFilter method. It is then up to you to add or not the value of AMember to the AObj that is being serialized. Sincerely, Andrea Aha, i tried the JSONName before, did not work, but now i found out why, it's in the MARS.Core.JSON.pas, not in the MARS.Core.Attributes.pas The function ToJSONFilter(const AMember: TRttiMember; const AObj: TJSONObject): Boolean; works also, thanks! Edited 20 hours ago by mvanrijnen Share this post Link to post