#1 2025-04-29 13:26:16

anouri
Member
Registered: 2024-02-11
Posts: 100

TSynDictionary.SaveToJson generate invalid json

Hi AB, many thanks to great framework.

I have
FClients: TSynDictionary;

TSynDictionary.SaveToJson generate below json :

{1:{"ConnectionId":1,"ComputerName":"Test"},2:{"ConnectionId":2,"ComputerName":"Comp"}}

which is not valid json.

how can I remove "{1:","{2:", ... from Result.

Last edited by anouri (2025-04-29 13:28:34)

Offline

#2 2025-04-29 14:47:12

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,005
Website

Re: TSynDictionary.SaveToJson generate invalid json

How is your TSynDictionary initialized? Which data?

Edit:
I guess you had something like TIntegerDynArray as keys.
I have fixed the serialization of such content:
https://github.com/synopse/mORMot2/commit/240b293da4e7

Offline

#3 2025-04-30 04:31:14

anouri
Member
Registered: 2024-02-11
Posts: 100

Re: TSynDictionary.SaveToJson generate invalid json

Yes.

type
  TClient = record
    ConnectionId: THttpServerConnectionID;
    ComputerName: string;
  end;

  TClients = array of TClient;

  TInt64DynArray = array of Int64;

  FClients := TSynDictionary.Create(TypeInfo(TInt64DynArray), TypeInfo(TClients));

Offline

#4 2025-04-30 04:45:06

anouri
Member
Registered: 2024-02-11
Posts: 100

Re: TSynDictionary.SaveToJson generate invalid json

Solved with this commit.
Thank you so much

Offline

#5 2025-04-30 14:08:24

anouri
Member
Registered: 2024-02-11
Posts: 100

Re: TSynDictionary.SaveToJson generate invalid json

After upgrading to the new version I encountered another problem. madexcept stopped working and to solve the issue I had to use the following option:
TAppLog.Family.Level := [sllInfo, sllWarning]
instead of
TAppLog.Family.Level := LOG_VERBOSE
I actually used mormot logging feature in a Windows desktop project.

Last edited by anouri (2025-04-30 14:15:27)

Offline

#6 2025-04-30 14:32:55

anouri
Member
Registered: 2024-02-11
Posts: 100

Re: TSynDictionary.SaveToJson generate invalid json

I tried
TAppLog.Family.StackTraceUse := stOnlyManual;
and
TAppLog.Family.LevelStackTrace := [];

with not success!

Is there a way to set TSynLog that don't capture exceptions?

Offline

#7 2025-04-30 19:08:43

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,005
Website

Re: TSynDictionary.SaveToJson generate invalid json

Nothing changed about all exception are intercepted by the framework, AFAICT.

You can either use instead LOG_VERBOSE - [sllException, sllExceptionOs]
or set the NOEXCEPTIONINTERCEPT conditional.

I have also just added SynLogNoExceptionIntercept global variable:
https://github.com/synopse/mORMot2/commit/c51b76eff

Offline

#8 2025-05-01 05:39:59

anouri
Member
Registered: 2024-02-11
Posts: 100

Re: TSynDictionary.SaveToJson generate invalid json

Very useful. Thank you so much.

Offline

#9 2025-05-01 07:57:23

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,005
Website

Re: TSynDictionary.SaveToJson generate invalid json

Out of curiosity, which function of MadExcept do you really need, which is not in TSynLog exception interception?

Offline

#10 2025-05-01 09:17:41

anouri
Member
Registered: 2024-02-11
Posts: 100

Re: TSynDictionary.SaveToJson generate invalid json

I have huge project implemented by delphi vcl with 600 forms.
I use madexcept to catch and show unhandeded exceptions.
if mormot can handle this. I mean if there is onException Event handler or somthing like this. I can replace it with mormot.
Myabe OnBeforeException event can help.


I also show call stack to end user when exception is unhandeled:

https://gist.github.com/a-nouri/8ddfe5d … 8bdf28ae69

show_error function shows error in form to end user. and then sent to my website and I save unhandedled exceptions in table in web site by php.

Last edited by anouri (2025-05-01 09:33:37)

Offline

Board footer

Powered by FluxBB