Session property array change type

I am storing a list of long elements in a session.props.custom. I make the whole list then store it in the property.

When I check the type of the elements just after, the elements are unicode. Is this expected behavior? I just wanted to be sure so I can know it will always be unicode instead of long or whatever.

Thanks

The type of the elements will depend on how they're populated. Perspective's property model is ultimately backed by JSON, so elements can be numbers, strings, booleans, or nulls. Those properties then get mapped to Jython types when you read them in scripts, and unicode is the string type used.

These were populated with longs, so you're saying that JSON doesn't support longs therefore it casts it to unicode?

No. I'm saying you need to provide more details on what "populated with longs" means to you.

Given one button:

def runAction(self, event):
	self.view.custom.test = [
		"1",
		1,
		long(1),
		1.0,
		True
	]

You get the following:

Perhaps misleadingly, if you run this without saving:

def runAction(self, event):
	for p in self.view.custom.test:
		system.perspective.print("%s - %s" % (repr(p), type(p)))

Type information appears to be preserved:

11:43:14.112 INFO -- u'1' - <type 'unicode'>
11:43:14.112 INFO -- 1 - <type 'int'>
11:43:14.112 INFO -- 1L - <type 'long'>
11:43:14.112 INFO -- 1.0 - <type 'float'>
11:43:14.112 INFO -- True - <type 'bool'>
11:43:14.112 [Browser Thread: 17eb01f7-0d4f-4fc8-b887-21de0a965dbf] INFO Perspective.Designer.Workspace -- True - <type 'bool'>

But then if you save and reopen the view:

11:43:58.816 INFO -- u'1' - <type 'unicode'>
11:43:58.816 INFO -- 1L - <type 'long'>
11:43:58.816 INFO -- 1L - <type 'long'>
11:43:58.816 INFO -- 1L - <type 'long'>
11:43:58.816 INFO -- True - <type 'bool'>

Be aware that if you stick an object that isn't a Perspective-compatible type, then it will be stringified and no longer be an object.

If you need to preserve original objects associated with views/pages/sessions, you need my Integration Toolkit's viewVarMap(), pageVarMap(), and/or sessionVarMap() functions.