Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Offline always returns string values

    SmartClient Version: SNAPSHOT_v13.1d_2024-09-15/AllModules Development Only (built 2024-09-15)
    SmartClient Version: v13.0p_2024-09-14/AllModules Development Only (built 2024-09-14)

    Hello, I just noticed that, after storing a number or boolean value with Offline api, when retrieving those values they became strings. Is it expected?

    You may try with this test case:

    Code:
    isc.Offline.put("aNumber", 5);
    isc.Offline.put("aBoolean", true);
    
    let aNumber = isc.Offline.get("aNumber");
    let aBoolean = isc.Offline.get("aBoolean");
    
    isc.say("aNumber is a Number? " + isc.isA.Number(aNumber) + "<br>or is a String? " + isc.isA.String(aNumber)
        + "<br>aBoolean is a Boolean? " + isc.isA.Boolean(aBoolean))

    #2
    Yes, all localStorage is effectively String storage, so you need to have a mechanism of retaining type if type is important. Typically, this is done by encoding to JSON or XML.

    If you use our JSONEncoder, it can also round-trip Dates and keep the distinction between a date, datetime or time value.

    Comment


      #3
      thanks for the clarification, it's not actually a problem, it's just that the doc says "only primitive values - Strings, numbers and booleans - can be stored", so at first I thought that for those the type would be retained. Maybe a note could be beneficial.

      Comment


        #4
        Yes, a clarifying note is already being added to the documentation, as it does sound as if the type would be round-tripped, whereas what it actually meant was that you can't directly store an Object without serializing it.

        Comment


          #5
          As of tomorrow, the docs are updated with some clarifications, if you want to take a look. Thanks for pointing this out!

          Comment


            #6
            Now there is no risk of misunderstanding in the documentation, thanks!

            Comment

            Working...
            X