Hi all,


I'm experiencing an issue in our mobile application.


We have a transaction with a long form split up into separate screens. Since this is just one of the many transactions (with differing fields) we have to support in our mobile app, we decided to have the transaction details as a string column in our local storage and we use JSON Serialize and Deserialize to store and retrieve the values.


The scenario to reproduce the problem is as follows:


We input the Customer.BirthDate variable in Screen1, serializing the Customer object into the local storage when we proceed to the next screen, in Screen2 we have a field that is also populated by the Customer.Birthdate variable. But at this point Screen2's birthday field is blank. Upon checking, the serialization works as expected (the input would be written into localstorage, although the timezone is shifted), but the deserialization returns the default value.


One of the solutions I have in mind is to have a separate local storage table for this type of transaction, but as much as possible we would like to minimize this as we would most likely have other transactions that would require date fields/variables.


Please see below for the screenshots



1. Serialization success

2. Local Storage (chrome dev tools)

3. Retrieve from Local Storage (onAfterFetch)


4. Deserialize problem


Edit: Resized images and added Outsystems 11 tag

Hi Kevin,

Can you check the "Name In JSON" property of the structure variable of birthdate. May be that could be the reason.

Regards,

Koushik. 

Koushik Prathi wrote:

Hi Kevin,

Can you check the "Name In JSON" property of the structure variable of birthdate. May be that could be the reason.

Regards,

Koushik. 

Hi Koushik,


Thanks for the quick reply. I've checked the Name in JSON property and it is set to blank. I've tested both "BirthDate" and "birthDate" but the result is still the same.

Apologies, I forgot to note a couple other things that might help in replicating the problem. We're using Outsystems 11. The birthdate field is set to "Date" data type. What other information would you need to know that would help?


I'll see if I can replicate this and post the .oml file. 


Cheers,

Kevin

Hi,


To resolve this issue, I've created a temporary variable with "Date" datatype for the field, then I've converted the structure's datatype to "Text". I manually convert between those datatypes before doing serialization.


Cheers,

Kevin

Hi Kevin,


Have you looked into some functions like TextToDate() while you are converting the JSON string back into Outsystems object?

If you check in the example, for all input value that can't be automatically transferred back into DateValue would be viewed as the default date value #1900-1-1# just as what you have received.


Examples

TextToDate("2002-01-01") = #2002-01-01#
TextToDate("2002/01/01") = #2002-01-01#
TextToDate("2002.01.01") = #2002-01-01#
TextToDate("2002-25-01") = #1900-01-01#
TextToDate("2002/02/31") = #1900-01-01#
TextToDate("10000.01.01") = #1900-01-01#


Therefore, before converting the JSON string to date value, you can make use of the TextToDateValidate to verify whether it can or cannot be converted, if that is not a good format, consider using some acceptable format while generating the JSON.


Cheers,

Hillman

@Hillman: I'd consider that bad advice. At best it's a workaround, but the JSON serializing/deserializing should just work.

@Kevin: this is a weird problem, I would suggest you to create a minimal example that shows this problem, and send it to OutSystems Support. That said, I don't understand why you just don't create a proper data model to store the data in, instead of converting JSON back and forth.

Kilian Hekhuis wrote:

@Hillman: I'd consider that bad advice. At best it's a workaround, but the JSON serializing/deserializing should just work.

@Kevin: this is a weird problem, I would suggest you to create a minimal example that shows this problem, and send it to OutSystems Support. That said, I don't understand why you just don't create a proper data model to store the data in, instead of converting JSON back and forth.

Hi Kilian,


I'll post an .oml file once I replicate the behavior.


As for the data modeling, the background is that we have an internal mobile app which sort of has a "shopping cart" of transactions stored locally, and then we synchronize it once the customer queues up.I realize this may be a red flag when it comes to synchronization best practices, but we would like to avoid having to continuously persist parts of a transaction while proceeding on the app's screens.


That said, we originally had different local storage tables defined for the categories of transactions, and we manually strung up the relations between them. It became quite unwieldy when we wanted to reuse the screens for transactions of differing categories (which had different fields across them). I think we're incurring a performance cost due to the serialization happening but so far the app isn't becoming unresponsive.  


Cheers,

Kevin