<list-deserialization>

Purpose/Function

Convert a string conforming to <list-serialization> serialization back into its original object.

The constraint on this string is that all its simple members must be primitiveAssignable. The string may have nested collection or map representations, as long as these always bottom out in objects with string constructors of a type defined in the Java SDK.

Attributes

NAME

TYPE

DEFAULT VALUE

DESCRIPTION

serialization

java.lang.String

(required)

representation of object to convert

name

java.lang.String

(required)

name of variable to which to assign the result

global

boolean

false

assign to global frame

declare

boolean

true

declare the variable name rather than assign to existing variable

separator

java.lang.String

", "

separates elements in a collection or map

assignment

java.lang.String

"="

assigns value to key in map

cStartDelim

java.lang.String

"["

indicates beginning of collection

cEndDelim

java.lang.String

"]"

indicates end of collection

mStartDelim

java.lang.String

"{"

indicates beginning of map

mEndDelim

java.lang.String

"}"

indicates end of map

NOTE

While the delimiters and assignment operator are all of type string, they are constrained to be a single, non-white-space character. The separator string may have only one non-white-space character in it.

Elements

TAG

TYPE

COUNT

DESCRIPTION

<pattern>

java.util.List

0:1

see note below

NOTE

The pattern list can contain either fully qualified names for Java primitive types (as the example below), or actual sample instances of that type. It is used as follows:

  • As each value string is accessed, the next type in the pattern list is used to construct the actual value;
  • The pattern list is cycled through (hence the values are converted modulo the pattern list);
  • Conversion takes place using depth-first recursion; the example below also illustrates this;
  • A single type in the pattern list, of course, converts all values to that type;
  • Calling this task without a pattern list will simply generate an object with java.lang.String values.

ReturnValues

None.

Examples

<ogrescript name="test-deserialize-list">
	<declare name="list">
		<list>
			<list>
				<value type="double">-.408293</value>
				<value type="boolean">false</value>
				<list>
					<value>an internal list string</value>
					<value>another internal list string</value>
				</list>
			</list>
			<value type="int">483</value>
			<value type="long">8822938409128</value>
			<map>
				<map-entry key="a">
					<list>
						<value>an internal map string</value>
						<value text="" />
					</list>
				</map-entry>
			</map>
		</list>
	</declare>
	<list-serialization object="${list}" name="ser" mStartDelim="(" mEndDelim=")" separator="; " assignment=":" />
	<list-deserialization serialization="${ser}" name="list" declare="false" mStartDelim="(" mEndDelim=")" separator="; " assignment=":">
		<pattern>
			<value>java.lang.Double</value>
			<value>java.lang.Boolean</value>
			<value>java.lang.String</value>
			<value>java.lang.String</value>
			<value>java.lang.Integer</value>
			<value>java.lang.Long</value>
			<value>java.lang.String</value>
			<value>java.lang.String</value>
		</pattern>
	</list-deserialization>
	<echo message="${list}" stdout="true" />
</ogrescript>

The <echo> statement should produce this output:

<collection type="class java.util.ArrayList">
  <collection type="class java.util.ArrayList">
    <element type="class java.lang.Double">-0.408293</element>
    <element type="class java.lang.Boolean">false</element>
    <collection type="class java.util.ArrayList">
      <element type="class java.lang.String">an internal list string</element>
      <element type="class java.lang.String">another internal list string</element>
    </collection>
  </collection>
  <element type="class java.lang.Integer">483</element>
  <element type="class java.lang.Long">8822938409128</element>
  <map type="class java.util.HashMap">
    <entry key="a">
      <collection type="class java.util.ArrayList">
        <element type="class java.lang.String">an internal map string</element>
        <element type="class java.lang.String"/>
      </collection>
    </entry>
  </map>
</collection>
  • No labels