JSON Converter for FIXEdge Java Endpoints

JSON Converter for FIXEdge Java Endpoints

Starting from FIXEdge Java 1.12.0, a new feature has been introduced that enables seamless conversion between FIX and JSON formats. This functionality is based on the FIX Trading Community standard for encoding FIX using JSON, and is fully integrated into the Business Layer (BL) via Groovy scripting.

Feature Overview

  • Bidirectional conversion: Supports both FIX-to-JSON and JSON-to-FIX transformations.

  • Dictionary-driven: Conversion logic is based on the FIX dictionary definitions.

  • Scriptable: Can be used directly in BL Groovy scripts for flexible routing and transformation logic.

⚠️ Note: The JSON converter is disabled by default and must be explicitly enabled in the configuration.


🔧Enabling the JSON Converter

To enable JSON conversion in FIXEdge Java:

  1. Open the file:
    [FEJ distribution]/conf/msg-converter.properties
    Set the following property to true:

converter.dictionary.json.init = true
  1. Open the file:
    [FEJ distribution]/conf/spring/custom-ext.xml
    In the section titled "Map for beans, which will be accessible in BL Groovy scripts", add the following entry: <entry key="jsonConverter" value-ref="jsonConverter"/>

<!-- Map for beans, which will be accessible in BL Groovy scripts --> <util:map id="customBLBeans" key-type="java.lang.String"> <entry key="jsonConverter" value-ref="jsonConverter"/> </util:map>
  1. Restart FIXEdge Java to apply the changes.

💡Examples of Business Layer configuration for JSON converter


✅Example: Using JSON Converter in Business Layer

The following example demonstrates a simple BL configuration that:

  • Converts a FIX message from session1 (FIX.4.4) to JSON and routes it to Topic1.

  • Converts a JSON message from Topic2 to FIX (FIX.4.4) and routes it to session2.

import com.epam.fej.converter.JsonConverter import com.epam.fej.routing.RoutingContext import com.epam.fej.routing.rules.MessageRoutingRule import com.epam.fej.routing.rules.RuleAction import com.epam.fej.routing.rules.SourceCondition import groovy.json.JsonSlurper RoutingContext rc = routingContext as RoutingContext; [ // Rule 1: Convert FIX.4.4 from session1 to JSON and send to Topic1 new MessageRoutingRule( "Route FIX.4.4 from session1 to Topic1", { params -> params.getId() == "session1" } as SourceCondition, null, { ctx -> // method convertFromFIX returns JSON string from FIX message def jsonString = jsonConverter.convertFromFIX(ctx.getMessage(), "FIX.4.4") ctx.messageEvent.setHeader("JMS_BYTE_ARRAY", jsonString.getBytes("UTF-8")) rc.getDestinationById("Topic1").each { adapter -> adapter.send(ctx.messageEvent) } ctx.exit() } as RuleAction ), // Rule 2: Convert JSON from Topic2 to FIX.4.4 and send to session2 new MessageRoutingRule( "Route JSON from Topic2 to session2 as FIX.4.4", { params -> params.getId() == "Topic2" } as SourceCondition, null, { ctx -> def jsonBytes = ctx.messageEvent.getHeader("JMS_BYTE_ARRAY") // method convertToFIX converts byte array to the FIX message (FIXFieldList) def fixMessage = jsonConverter.convertToFIX(jsonBytes, "FIX.4.4") rc.getDestinationById("session2").each { adapter -> adapter.send(fixMessage) } ctx.exit() } as RuleAction ) ]

✅Example: Using JSON Converter for custom FIX dictionary

The following example demonstrates a simple BL configuration that:

  • Uses custom FIX dictionary FIXLatest-2 for FIX to JSON conversion

  • Converts a FIX message from session1 (custom dictionary FIXLatest-2) to JSON and routes it to queue JMS_OUT_Q and topic JMS_OUT_T.

new MessageRoutingRule( "Route msg with custom dictionary to JMS", { params -> def validSessions = ["session1"] return validSessions.contains(params.getId()) } as SourceCondition , null, { ctx -> // method convertFromFIX returns JSON string from FIX message def jsonString = jsonConverter.convertFromFIX(ctx.getMessage(),"FIXLatest-2"); ctx.messageEvent.setHeader("JMS_BYTE_ARRAY", jsonString.getBytes()) rc.getDestinationById("JMS_OUT_Q").each { adapter -> adapter.send(ctx.messageEvent) } rc.getDestinationById("JMS_OUT_T").each { adapter -> adapter.send(ctx.messageEvent) } ctx.exit() } as RuleAction),

✅Example: Automatically Determining FIX Version for JSON Conversion

The following example demonstrates a simple BL configuration that:

  • Does FIX to JSON conversion for messages from the list of FIX sessions: session1, session2, session3, session4.

  • Automatically defines fixVersion for each FIX session / FIX message.

  • Converts a FIX message using corresponding dictionary to JSON and routes it to the topic JMS_OUT_T.

new MessageRoutingRule( "Route msg to JMS", { params -> def validSessions = ["session1", "session2", "session3", "session4"] return validSessions.contains(params.getId()) } as SourceCondition , null, { ctx -> def fixVersion = "FIXLatest" try { if (ctx.sourceParams.&getAllSessionParams) { def sessionParams = ctx.sourceParams.getAllSessionParams() def fixVersionValue = sessionParams.getFixVersion().id if (fixVersionValue == "FIXT11") { fixVersion = sessionParams.getAppVersion().id logger.debug("fixAppVersionId : ${fixVersion}") } else { fixVersion = fixVersionValue } logger.debug("fixVersionId : ${fixVersion}") } } catch (Exception e) { logger.error("Error retrieving version info", e) } // method convertFromFIX returns JSON string from FIX message def jsonString = jsonConverter.convertFromFIX(ctx.getMessage(),fixVersion); ctx.messageEvent.setHeader("JMS_BYTE_ARRAY", jsonString.getBytes()) rc.getDestinationById("JMS_OUT_T").each { adapter -> adapter.send(ctx.messageEvent) } ctx.exit() } as RuleAction),

✅Example: Working with JSON object in Business Rules

The following example demonstrates how to convert JSON string to the JSON object

import groovy.json.JsonSlurper new MessageRoutingRule( "Route msg from JMS Queue", { params -> return params.getId() == "JMS_IN_Q" }, null, { ctx -> def fixFieldList = ctx.message if (ctx.messageEvent.getHeader().containsKey("JMS_BYTE_ARRAY")) { // Parsing JSON string from messageEvent Header to the JSON object def json = new JsonSlurper().parseText(new String(ctx.messageEvent.getHeader("JMS_BYTE_ARRAY"), "UTF-8")) // Acessing JSON BeginString field to get fixVersion String fixVersion = json.Header.BeginString if (fixVersion != null && fixVersion.startsWith("FIXT")) { fixVersion = json.Header.AppVersion } if (fixVersion != null) { fixVersion = fixVersion.replace(".","") } else { fixVersion = "FIXLatest" } logger.debug("fixVersion=${fixVersion}") fixFieldList = jsonConverter.convertToFIX(ctx.messageEvent.getHeader("JMS_BYTE_ARRAY"),fixVersion) } rc.getDestinationById("session2").each { adapter -> adapter.send(fixFieldList) ctx.exit() } } as RuleAction)