The Akwatype types allows to declare that a field corresponds to an object list.

For example a team with a list of members :

type Team{
   members:[Person]
}

type Person{
   name:String
   firstName:String
   age:Integer
}


A Json corresponding to this description could be :

{
  "members": [
    {
      "name": "Gaillard",
      "firstName": "Lea",
      "age": 25
    },
    {
      "name": "Dupont",
      "firstName": "Philippe",
      "age": 55
    }
  ]
}

 

Declaration of a Map

A Map, or Dictionary,  is a collection of key / value pairs, it's a common valid Json Structure.

In the following Json example we have used the person's name as the key to the Map

{
  "members": {
    "Gaillard": {
      "firstName": "Lea",
      "age": 25
    },
    "Dupont": {
      "firstName": "Philippe",
      "age": 55
    }
  }
}


To perform this transformation you can use Awatype's toMap function.

This function is used following the declaration of a selected field name for a facade.

The previous example would result in the following statement:

facade TeamDTO on Team{
    members::PersonDTO toMap(name, -)
}

facade PersonDTO on Person{
    name
    firstName
    age
}

The toMap function requires two parameters

  • The name of the field to be used as a key in the facade associated with the field to which the toMap function is applied.
  • A field selector that can take the following values
    • The minus sign (-) to indicate that all fields are taken except the field used as a key.
    • The star sign (*) to indicate that all fields are taken (including the field used as a key)
    • The name of a scalar field to create a map with scalar values.
      • In this particular case, the facade associated with the list field that you want to transform into a Map should have only two fields (the one used for the key and the one used for the value).
Example of a Map with scalar values
facade TeamDTO on Team{
    members::PersonAgeDTO toMap(name, age)
}

facade PersonAgeDTO on Person{
    name
    age
}

{
  "members": {
    "Gaillard": 25,
    "Dupont": 55
  }
}