narek adonts Well-Known Member Licensed User Longtime User Sep 10, 2015 #1 Hi, I would like to know if there is away to convert a json string to custom Type and vice versa (something like google gson). I think the solution is implemented already as Read/WriteB4X object are doing something similar but it saved as bytes. So maybe somebody know the solution behind. Narek
Hi, I would like to know if there is away to convert a json string to custom Type and vice versa (something like google gson). I think the solution is implemented already as Read/WriteB4X object are doing something similar but it saved as bytes. So maybe somebody know the solution behind. Narek
Erel B4X founder Staff member Licensed User Longtime User Sep 10, 2015 #2 You can write a simple method that converts the json string to a custom type. It will not happen automatically. Another option is to use WriteB4XObject instead of json: https://www.b4x.com/android/forum/threads/server-send-and-receive-objects.37206/#content The above example uses WriteObject but it should be trivial to change it to use WriteB4XObject. Upvote 0
You can write a simple method that converts the json string to a custom type. It will not happen automatically. Another option is to use WriteB4XObject instead of json: https://www.b4x.com/android/forum/threads/server-send-and-receive-objects.37206/#content The above example uses WriteObject but it should be trivial to change it to use WriteB4XObject.
narek adonts Well-Known Member Licensed User Longtime User Sep 10, 2015 #3 I know about WriteB4XObject but for some tasks is to slow. I though maybe you will disclose the algorithm of converting a type to a string )) Upvote 0
I know about WriteB4XObject but for some tasks is to slow. I though maybe you will disclose the algorithm of converting a type to a string ))
Erel B4X founder Staff member Licensed User Longtime User Sep 10, 2015 #4 Serializing objects with WriteB4XObject / ReadB4XObject will be faster than serializing objects with json. Upvote 0
Serializing objects with WriteB4XObject / ReadB4XObject will be faster than serializing objects with json.
narek adonts Well-Known Member Licensed User Longtime User Sep 10, 2015 #5 Are you sure? Are there any numbers? I switched to JSON as I thought that maybe one day I will use another app to build the server instead of B4j. Last edited: Sep 10, 2015 Upvote 0
Are you sure? Are there any numbers? I switched to JSON as I thought that maybe one day I will use another app to build the server instead of B4j.
Erel B4X founder Staff member Licensed User Longtime User Sep 10, 2015 #6 narek adonts said: Are you sure? Are there any numbers? Click to expand... I didn't make any performance tests. Go ahead create a small test and post the results. Upvote 0
narek adonts said: Are you sure? Are there any numbers? Click to expand... I didn't make any performance tests. Go ahead create a small test and post the results.
narek adonts Well-Known Member Licensed User Longtime User Sep 14, 2015 #7 You were right. It is faster and it much smaller then json string(compressed). Will be happy to use it. But maybe you should make the WriteB4XObject/ReadB4XObject open source or publish the algorithm so we will be able to use it if we will decide to switch the Server side app. Narek Upvote 0
You were right. It is faster and it much smaller then json string(compressed). Will be happy to use it. But maybe you should make the WriteB4XObject/ReadB4XObject open source or publish the algorithm so we will be able to use it if we will decide to switch the Server side app. Narek