Official Content

Specifies the way collections are serialized in Json format.

Values

Sequence Serializes as a plain sequence of collection elements.
Wrapped Includes the collection name item. This is the default value.

Scope

Objects: Structured Data Type
Generators: .NET, .NET Framework, Java
Level: SDT level node

Description

The Json Collection Serialization property is available in the SDT node that has been defined as a collection by selecting the Is Collection checkbox.

JsonCollectionSerializationProperty_png

Note: In Java and .NET Framework generators, this property is only taken into account when the Structured Data Type (SDT) is a parameter of an API object. It is not taken into account in Procedures or Data Providers exposed as REST.

Runtime/Design time

This property applies only at runtime.

Samples

Suppose you have defined an SDT called Countries, as shown in the image above. 

Next, you define a Procedure object called CountryList as follows:

Variables:

Countries     (Type:Countries)
country       (Type:Countries.Country)

Rules:

Parm(out:&Countries);

Source:

&country = new()
&country.CountryName = "UY"
&Countries.Country.Add(&country)

&country = new()
&country.CountryName = "BR"
&Countries.Country.Add(&country)

Then in the Service Source of the API object, you define the following:

Countries{
    [RestVerb(GET)]
    ListCountries(out:&Countries) => ListCountries(&Countries);
    }

When running by pressing F5, you will be able to display one of the following, depending on the value set in the Json Collection Serialization property:

  • Wrapped:
     {
      "Countries": [
        {
          "CountryName": "UY"
        },
        {
          "CountryName": "BR"
        }
      ]
    }
  • Sequence:
    [
      {
        "CountryName": "UY"
      },
      {
        "CountryName": "BR"
      }
    ]

See Also

Procedures as Rest Web Services in GeneXus
Data Providers as Rest Web Services in GeneXus

Last update: February 2024 | © GeneXus. All rights reserved. GeneXus Powered by Globant