Let's assume we have this FinancialInformation type with two fields (turnoverBeforeTax and amoutOfTaxes) of type Amount

type FinancialInformation{
    fiscalYear:Integer
    turnoverBeforeTax:Amount
    amountOfTaxes:Amount
}            

type Amount{
    value:Decimal
    currency:String
}   

A Json example corresponding to this type could be 

{
  "fiscalYear": 2021,
  "turnoverBeforeTax": {
    "value": 2535210,
    "currency": "EUR"
  },
  "amountOfTaxes": {
    "value": 507042,
    "currency": "EUR"
  }
}

 

For some reason, we need to exchange information about the amounts in an amout list as in the Json example below

{
  "fiscalYear": 2021,
  "financialStatement": [
    {
      "value": 2535210,
      "currency": "EUR",
      "code": "01"
    },
    {
      "value": 507042,
      "currency": "EUR",
      "code": "02"
    }
  ]
}

 

To do this, we can describe a facade that uses the mergeTo statement on the fields of the type we want to group in the fiancialStatement list.

  • The first thing to do is to add an additional untyped list field ( no type name between the [ ] )
    • note: To allow maximum flexibility in the grouping of fields, the target list of mergeTo statements is not typed
  • Then list all the fields to be retained for this facade, including the fields to be grouped in the list and the target list field.
  • Add the mergeTo instruction to the fields to put in the list.
    • the mergeTo instruction has two parameters
      • the name of the target list field
      • a marker that allows to define which field to use and with which value to determine the original field corresponding to the data found in the list
        • "code":"01" correspond à turnoverBeforeTax
        • "code":"02" correspond à amountOfTaxes
  • Describe an AmountDTO facade with an additional field code
facade FinancialInformationDTO on FinancialInformation{
    additionalFields {
        financialStatement:[]
    }
fiscalYear
financialStatement turnoverBeforeTax::AmountDTO mergeTo(financialStatement,marker:[code:"01"]) amountOfTaxes::AmountDTO mergeTo(financialStatement,marker:[code:"02"]) } facade AmountDTO on Amount{ additionalFields { code:String } value currency }