Aller au contenu

Syntaxe des mappers

Dernière révision : 28 octobre 2026 · Nouveautés de la plateforme

Un mapper transforme un message reçu (JSON, XML, FIX, MT, MX, FpML, CSV ou objet Java) en objet cible, par exemple un trade au format pivot. L'éditeur l'affiche en grille ou en blocs, et l'enregistre en XML : cette page décrit ce XML et le langage de ses expressions, tels que le moteur les exécute.

Structure d'un mapper

Un mapper déclare d'abord ses templates, puis ses instructions, exécutées dans l'ordre, et se termine par sa sortie, obligatoire. Chaque instruction, paramètre ou sortie porte une seule valeur.

<mapper>
  <template name="nomDuTemplate"> <input name="parametre"/> ... <output>...</output> </template>
  <setVariable name="doc"> ...une valeur... </setVariable>
  <output> ...une valeur... </output>
</mapper>

Les valeurs

ÉlémentCe qu'il rend
<input/>le message reçu
<simple>expression</simple>le résultat d'une expression ; une constante s'écrit 'NEW', 1 ou null
<variable ref="doc"/>la valeur d'une variable, nommée sans #
<mappings target="pivot.TradePivot"> <mapping target="champ">...</mapping> </mappings>un objet de la classe cible, construit champ par champ
<list> ... </list>une liste de valeurs
<choice> <when expression="..."> <output>...</output> </when> <otherwise>...</otherwise> </choice>la valeur de la première branche dont la condition est vraie
<for from="variable" as="item" index="index"> <output>...</output> </for>une liste : une valeur par élément de la variable
<call template="t"> <parameter name="p">...</parameter> </call>le résultat d'un template

Les expressions

Une expression s'écrit dans <simple> et dans les attributs when/@expression et throw/@message. Une variable s'y lit avec # : un nom sans # n'est pas une variable et fait échouer l'exécution.

ÉcritureSens
#trade.tradeId #liste[0] #carte['k']champ d'un objet, élément d'une liste, valeur d'une carte (une clé absente rend null)
{'IRS':'InterestRateSwap','CDS':'CreditDefaultSwap'}[#type]une table de correspondance écrite dans l'expression
== != < > <= >= (eq ne lt gt le ge)comparaisons ; dans le XML, < s'écrit &lt; ou lt
and or notlogique ; préférer and à &&, qui doit être échappé dans le XML
+ - * / %calcul ; + concatène aussi deux textes
condition ? a : bternaire
#x ?: 'défaut'valeur par défaut : remplace null et aussi le texte vide
#x?.trim()navigation sûre : null au lieu d'une erreur si #x est null
#s.trim() #s.toUpperCase() #s.substring(0, 4) #s.length() #s.replace('a', 'b')méthodes des textes
#code matches '[A-Z]{3}'correspondance avec une expression régulière
new java.math.BigDecimal(#s)un nombre décimal à partir d'un texte
T(java.time.LocalDate).parse(#d).plusDays(2)une date à partir d'un texte ISO

Vide et null : une extraction XML ou JSON qui ne trouve rien rend un texte vide, jamais null ; on teste donc #x == ''. Une variable non déclarée vaut null, et une méthode appelée sur null est une erreur : #x?.trim() l'évite. Conversions : aucune n'est implicite ; un texte ne va pas dans un champ décimal sans new java.math.BigDecimal(...).

Lire un message

FormatLectureChemins
XML, XSD, MX, FpML<xmldoc:marshal><input/></xmldoc:marshal> puis <xmldoc:extract xpath="..."><variable ref="doc"/></xmldoc:extract>XPath 1.0 relatif au document, * désignant l'élément racine ; noms sans préfixe d'espace de noms ; multiple="true" rend tous les nœuds
JSON<json:parse><input/></json:parse> puis <json:extract path="$.product.productType">JSONPath ; un scalaire rend son texte, un objet ou un tableau rend un nœud ; le premier résultat sauf avec multiple="true"
FIX<fin:marshal format="FIX"><input/></fin:marshal> puis <xmldoc:extract xpath="...">XPath sur message/body/field[@name='LastPx'], groups[@name='NoSides']/group ; le séparateur barre verticale est accepté
MT<fin:marshal format="MT"><input/></fin:marshal>méthodes du message : #mt.getBlock4().getTagValue('32A')
CSVlu par le flux, en amont, en objet Javachamps de l'objet : #trade.getTradeId() ?: ''
Objet Java<input/>#v.champ

Glisser un champ de la source sur une ligne crée la lecture adaptée pour un document XML, JSON ou FIX. Pour une source CSV ou Java, l'éditeur écrit le nom du champ, à compléter en expression.

Construire l'objet cible

  • mappings crée un objet de la classe cible par son constructeur sans argument ; avec instance="variable", il complète l'objet de cette variable.
  • Chaque mapping écrit un champ (hérité compris) ; la valeur doit avoir le type du champ : aucune conversion n'est faite.
  • Une cible java.util.LinkedHashMap reçoit une entrée par mapping, utile pour produire un JSON libre.

Choix, boucles, templates et erreurs

  • Choix : terminez toujours par <otherwise> ; si aucune branche n'est vraie et qu'il n'y en a pas, l'exécution échoue. Les mappers des cas d'usage finissent par <otherwise><output><simple>null</simple></output></otherwise>.
  • Boucle : from est le nom d'une variable (pas une expression) qui contient une liste, un tableau, les nœuds d'une extraction multiple="true", ou une carte (chaque élément est alors une entrée : #item.key, #item.value) ; as vaut item et index vaut index par défaut.
  • Template : déclaré en tête avec ses <input name="..."/>, appelé par <call> avec un <parameter> par entrée.
  • Portée : un template et une boucle ne voient pas les variables du mapper ; ils ne voient que leurs paramètres, ou l'élément et l'index. Passez en paramètre ce dont ils ont besoin. Un choix et un rattrapage partagent les variables du mapper.
  • Erreurs : <try> est une instruction, placée parmi les <setVariable>. Si la valeur qu'il garde échoue, le premier <onException> dont l'<exception> correspond, par exemple java.lang.RuntimeException, exécute ses instructions, comme un <setVariable> de repli. Qu'elle réussisse ou non, la valeur gardée n'est rangée nulle part ; si aucun <onException> ne correspond, l'erreur poursuit son chemin. <throw exceptionType="java.lang.IllegalArgumentException" message="'trade refusé'"/>, instruction lui aussi, en lève une. Le message est une expression : un texte s'y met entre apostrophes.

Contrôles de l'éditeur

« Couverture » compte les lignes alimentées du résultat sur l'ensemble des champs de la cible ; « Non alimentés » n'affiche que les lignes sans valeur. La barre dit « Aucun problème », ou le nombre d'erreurs, à défaut celui des avertissements ; « Corriger » répare ce qui peut l'être. Les messages :

MessageNature
L'élément « … » n'a pas d'attribut « … ».erreur
Le champ « … » n'est alimenté par rien : l'exécution échouera.erreur
Le paramètre « … » de l'appel à « … » n'a pas de valeur.erreur
Le template « … » est appelé mais n'est pas déclaré.erreur
Le template « … » attend le paramètre « … », qui n'est pas fourni.erreur ; « Corriger » ajoute le paramètre, vide, à remplir
Le paramètre « … » n'est pas déclaré par le template « … ».avertissement
Le template « … » est déclaré plusieurs fois : le mapping ne se chargera pas.erreur
Le template « … » n'est jamais appelé.avertissement
« … » est déclaré mais jamais lu.avertissement
« … » est lu mais n'est déclaré nulle part.erreur
Ce choix n'a aucune branche « when ».erreur
Ce choix a plusieurs branches « otherwise ».erreur
La branche « otherwise » doit venir en dernier.erreur, réparée par « Corriger »
Le champ cible « … » est alimenté deux fois.erreur
« … » n'existe pas sur « … ».erreur
« … » n'existe pas dans « … ».avertissement

Exemples tirés des cas d'usage

ExpressionCe qu'elle fait
{'IRS':'InterestRateSwap','CDS':'CreditDefaultSwap'}[#productType.trim().toUpperCase()] ?: #productTypetraduit un code produit, et garde la valeur reçue si elle n'est pas dans la table
#notionalStr.trim() == '' ? null : new java.math.BigDecimal(#notionalStr.trim())un nominal décimal, ou null s'il est vide
#action.trim() == '' ? 'NEW' : #action.trim().toUpperCase()une valeur par défaut
#payer ? 'BUY' : 'SELL'un sens calculé à partir d'un booléen
#d.length() == 8 ? #d.substring(0, 4) + '-' + #d.substring(4, 6) + '-' + #d.substring(6, 8) : #dune date AAAAMMJJ remise au format ISO
new java.math.BigDecimal(#quantity).multiply(new java.math.BigDecimal(#price))un montant calculé
*/*/CdtTrfTxInf/IntrBkSttlmAmt/@CcyXPath d'un message MX : la devise du montant réglé
message/body/field[@name='LastPx']XPath d'un message FIX : le prix de la dernière exécution

Et ensuite

Documentation de la plateforme Clomoon, éditée par Clover Consulting · Mentions légales · Confidentialité · Contact
Skip to content

Mapper syntax

Last revised 28 October 2026 · Platform changelog

A mapper turns a received message (JSON, XML, FIX, MT, MX, FpML, CSV or Java object) into a target object, for instance a trade in pivot format. The editor shows it as a grid or as blocks, and saves it as XML: this page describes that XML and the language of its expressions, as the engine runs them.

Structure of a mapper

A mapper first declares its templates, then its instructions, run in order, and ends with its output, which is required. Each instruction, parameter or output carries a single value.

<mapper>
  <template name="templateName"> <input name="parameter"/> ... <output>...</output> </template>
  <setVariable name="doc"> ...a value... </setVariable>
  <output> ...a value... </output>
</mapper>

Values

ElementWhat it returns
<input/>the received message
<simple>expression</simple>the result of an expression; a constant is written 'NEW', 1 or null
<variable ref="doc"/>the value of a variable, named without #
<mappings target="pivot.TradePivot"> <mapping target="field">...</mapping> </mappings>an object of the target class, built field by field
<list> ... </list>a list of values
<choice> <when expression="..."> <output>...</output> </when> <otherwise>...</otherwise> </choice>the value of the first branch whose condition is true
<for from="variable" as="item" index="index"> <output>...</output> </for>a list: one value per element of the variable
<call template="t"> <parameter name="p">...</parameter> </call>the result of a template

Expressions

An expression is written in <simple> and in the when/@expression and throw/@message attributes. A variable is read there with #: a name without # is not a variable and makes the run fail.

SyntaxMeaning
#trade.tradeId #liste[0] #carte['k']field of an object, element of a list, value of a map (a missing key returns null)
{'IRS':'InterestRateSwap','CDS':'CreditDefaultSwap'}[#type]a lookup table written in the expression
== != < > <= >= (eq ne lt gt le ge)comparisons; in the XML, < is written &lt; or lt
and or notlogic; prefer and to &&, which must be escaped in the XML
+ - * / %arithmetic; + also joins two texts
condition ? a : bternary
#x ?: 'default'default value: replaces null and also the empty text
#x?.trim()safe navigation: null instead of an error when #x is null
#s.trim() #s.toUpperCase() #s.substring(0, 4) #s.length() #s.replace('a', 'b')text methods
#code matches '[A-Z]{3}'match against a regular expression
new java.math.BigDecimal(#s)a decimal number from a text
T(java.time.LocalDate).parse(#d).plusDays(2)a date from an ISO text

Empty and null: an XML or JSON extraction that finds nothing returns an empty text, never null; test it with #x == ''. An undeclared variable is null, and a method called on null is an error: #x?.trim() avoids it. Conversions: none is implicit; a text does not go into a decimal field without new java.math.BigDecimal(...).

Reading a message

FormatReadingPaths
XML, XSD, MX, FpML<xmldoc:marshal><input/></xmldoc:marshal> then <xmldoc:extract xpath="..."><variable ref="doc"/></xmldoc:extract>XPath 1.0 relative to the document, * standing for the root element; names without namespace prefix; multiple="true" returns every node
JSON<json:parse><input/></json:parse> then <json:extract path="$.product.productType">JSONPath; a scalar returns its text, an object or array returns a node; the first result unless multiple="true"
FIX<fin:marshal format="FIX"><input/></fin:marshal> then <xmldoc:extract xpath="...">XPath on message/body/field[@name='LastPx'], groups[@name='NoSides']/group; the vertical bar separator is accepted
MT<fin:marshal format="MT"><input/></fin:marshal>message methods: #mt.getBlock4().getTagValue('32A')
CSVread by the flow, upstream, into a Java objectobject fields: #trade.getTradeId() ?: ''
Java object<input/>#v.field

Dragging a source field onto a row creates the matching read for an XML, JSON or FIX document. For a CSV or Java source, the editor writes the field name, to complete as an expression.

Building the target object

  • mappings creates an object of the target class through its no-argument constructor; with instance="variable", it completes the object of that variable.
  • Each mapping writes a field (inherited ones included); the value must have the field's type: no conversion is done.
  • A java.util.LinkedHashMap target gets one entry per mapping, useful to produce free-form JSON.

Choices, loops, templates and errors

  • Choice: always end with <otherwise>; if no branch is true and there is none, the run fails. The use-case mappers end with <otherwise><output><simple>null</simple></output></otherwise>.
  • Loop: from is the name of a variable (not an expression) holding a list, an array, the nodes of a multiple="true" extraction, or a map (each item is then an entry: #item.key, #item.value); as defaults to item and index to index.
  • Template: declared at the top with its <input name="..."/>, called through <call> with one <parameter> per input.
  • Scope: a template and a loop do not see the mapper's variables; they only see their parameters, or the item and the index. Pass what they need as parameters. A choice and a catch share the mapper's variables.
  • Errors: <try> is a statement, placed among the <setVariable>. If the value it guards fails, the first <onException> whose <exception> matches, for instance java.lang.RuntimeException, runs its statements, such as a fallback <setVariable>. Whether it succeeds or not, the guarded value is stored nowhere; if no <onException> matches, the error carries on. <throw exceptionType="java.lang.IllegalArgumentException" message="'trade refused'"/>, also a statement, raises one. The message is an expression: a text goes between single quotes.

Editor checks

“Coverage” counts the fed rows of the result over all the fields of the target; “Not fed” shows only the rows without a value. The bar says “No issue”, or the number of errors, else the number of warnings; “Fix” repairs what it can. The messages:

MessageKind
Element "…" has no "…" attribute.error
Field "…" is fed by nothing: the run will fail.error
Parameter "…" of the call to "…" has no value.error
Template "…" is called but not declared.error
Template "…" expects parameter "…", which is not supplied.error; “Fix” adds the parameter, empty, to be filled in
Parameter "…" is not declared by template "…".warning
Template "…" is declared more than once: the mapping will not load.error
Template "…" is never called.warning
"…" is declared but never read.warning
"…" is read but declared nowhere.error
This choice has no "when" branch.error
This choice has several "otherwise" branches.error
The "otherwise" branch must come last.error, repaired by “Fix”
Target field "…" is written twice.error
"…" does not exist on "…".error
"…" does not exist in "…".warning

Examples from the use cases

ExpressionWhat it does
{'IRS':'InterestRateSwap','CDS':'CreditDefaultSwap'}[#productType.trim().toUpperCase()] ?: #productTypetranslates a product code, and keeps the received value when it is not in the table
#notionalStr.trim() == '' ? null : new java.math.BigDecimal(#notionalStr.trim())a decimal notional, or null when empty
#action.trim() == '' ? 'NEW' : #action.trim().toUpperCase()a default value
#payer ? 'BUY' : 'SELL'a direction computed from a boolean
#d.length() == 8 ? #d.substring(0, 4) + '-' + #d.substring(4, 6) + '-' + #d.substring(6, 8) : #da YYYYMMDD date turned into ISO format
new java.math.BigDecimal(#quantity).multiply(new java.math.BigDecimal(#price))a computed amount
*/*/CdtTrfTxInf/IntrBkSttlmAmt/@CcyXPath of an MX message: the currency of the settled amount
message/body/field[@name='LastPx']XPath of a FIX message: the last execution price

What next

Documentation for the Clomoon platform, published by Clover Consulting · Legal notice · Privacy · Contact