Written by

Cofounder at snext
Question Blaise ZARKA · Apr 15, 2020

%Library.ListOfDataTypes to $LIST conversion

Hi,
Do you know the best way to convert a %Library.ListOfDataTypes instance to a $LIST format string?

Thanks,
Blaise

Comments

Eduard Lebedyuk · Apr 15, 2020

I think fairly straightforward approach works best

set l = ##class(%ListOfDataTypes).%New()
do l.Insert(1)
do l.Insert(2)
do l.Insert(4)
set lb = ""
for i=1:1:l.Count() { set lb = lb _ $lb(l.GetAt(i)) }
zw lb
>lb=$lb(1,2,4)
0
Blaise ZARKA  Apr 15, 2020 to Eduard Lebedyuk

thanks @Eduard Lebedyuk 
Yes it works great. that's the way we did it. So no direct straight serialization system function. ;-)

0
Eduard Lebedyuk  Apr 15, 2020 to Blaise ZARKA

There is actually. %GetSerial method builds a $lb from %ListOfDataTypes and %SetSerial does the reverse.

Both of these methods are private though. You can subclass %ListOfDataTypes and publish them.

0
Blaise ZARKA  Apr 16, 2020 to Eduard Lebedyuk

Oh great!
Please InterSystems developers, make these useful methods public and supported ;-)

0
Eduard Lebedyuk  Apr 16, 2020 to Blaise ZARKA

You can request new features/enhancements in WRC tickets.

0
Eduard Lebedyuk  Apr 16, 2020 to Blaise ZARKA

%Collection classes are internal and not to be used.

0
Blaise ZARKA  Apr 16, 2020 to Eduard Lebedyuk

You're sure about that? I understand these methods should only be used when the list property comes from a %Persistent object, but new instance with %New method is not allowed.

0
Eduard Lebedyuk  Apr 16, 2020 to Blaise ZARKA

Well, %Collection classes are the implementation of these constructs:

  • Property X As List Of Type
  • Relationships

You can call their methods but do not explicitly create objects of these classes.

0
Evgeny Shvarov  Apr 16, 2020 to Blaise ZARKA

And you can request it here in case you don't have WRC account or/if you want to make it public and get votes.

0
Robert Barbiaux  Sep 25, 2024 to Eduard Lebedyuk

For example (in open exchange package ks-iris-lib) :

/// list of data types exposing %GetSerial and %SetSerialClass ks.lib.collections.ListOfDataTypes Extends%Library.ListOfDataTypes
{

/// serialize object
Method %GetSerial(force As%Integer = 0) As%String
{
    return##super(force)
}

/// deserialize object
Method %SetSerial(serialized As%String) As%Status
{
    return##super(.serialized)
}

Storage Custom
{
<Type>%Library.CompleteCustomStorage</Type>
}

}
0