1. Tomas Beran
  2. PowerBuilder
  3. Thursday, 12 May 2022 11:48 AM UTC

Hi

Is there any way how to serialize/deserialize structure or class in PB?

I've found a thread which use PBNI but I'm looking for a pure PB solution. Is it even possible? The main issue is how to get/set values.

My goal is to find a better way how to transfer complex objects between PB and C# and JSON would be fine solution.

Do you have any idea how to do it?

 

Thank you

Accepted Answer
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Thursday, 12 May 2022 15:16 PM UTC
  2. PowerBuilder
  3. # Permalink

Hi Tomas;

  FYI:   That is what the new JSONParser object class was designed to help you accomplish.

Regards ... Chris

Comment
  1. Roland Smith
  2. Thursday, 12 May 2022 17:07 PM UTC
He wants to be able to 'export' the data currently in a structure to a JSON string. He didn't mention this but 'import JSON string into a structure' would be helpful as well.

I've done both using C++ PBNI but not using JSON strings. I used simple delimited strings.

  1. Helpful 1
  1. Tomas Beran
  2. Thursday, 12 May 2022 18:31 PM UTC
Hi Roland

I've seen the PBNI based solution. I've no experience with PBNI so I'm afraid of 3 things:

1. Is it UTF16 ready? Isn't there a hidden ascii call somewhere?

2. Is it independent to PBVM version, location, client computer settings etc? Does it work in 64bit project, with powerclient etc?

3. Isn't PBNI invoke a significant performance issue?
  1. Helpful
  1. Roland Smith
  2. Thursday, 12 May 2022 18:49 PM UTC
1. Yes. Just code the C++ as Unicode.

2. Yes. PBNI is not PB version dependent. You can compile the C++ as 64bit and it works fine with PB 64bit apps. I don't see why it wouldn't work with PowerClient.

3. No. There is no delay entering or exiting the C++ code. I have done timings to answer that.
  1. Helpful 1
There are no comments made yet.
Tomas Beran Accepted Answer Pending Moderation
  1. Thursday, 12 May 2022 15:32 PM UTC
  2. PowerBuilder
  3. # 1

Hi Chris

What do you mean with "new JSONParser"? Do you mean something which hasn't been published yet? I use PB2021 build 1509 but I can't find it. Can you give me a small example?

Plus I need a builder too (JSONGenerator). Actually I will use the builder more often because the structure will be a parameter of a C# wrapper method.

Thank you

Comment
  1. Tomas Beran
  2. Thursday, 12 May 2022 16:12 PM UTC
Maybe I'm overlooking something or we don't understand each other but I still can't see the generic JSON serializer.

My idea is following:

I've a structure:

s_struct

string a

string b

string c



Then code:

s_struct lst_str

lst_str.a = "apple"

lst_str.b = "orange"

lst_str.c = "pear"



string ls_json

js_json = JSONSerialize ( lst_str )



Now I expect in ls_json:

{"a":"apple","b":"orange","c":"pear"}



Ti think I can build the skeleton of the JSON through Classdefinition / ClassdefinitionObject and related objects but what I can't do is getting or setting variables because I have to use PBNI for this step which is what I don't want to do.
  1. Helpful
  1. Chris Pollach @Appeon
  2. Thursday, 12 May 2022 17:31 PM UTC
PB does not have a JSON Serialize type feature. You must be thinking of .NET based JSON. Instead, PB depends on you to use PowerScipt to perform that functionality. You could try a 3rd party tool though like this which has a serialize feature - for example: https://pbtoolbox.home.blog

  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.