ADR 0010: Typed Table Configuration
Author: Emir Boyacı • Scope: util-configuration
1. Context and Problem Statement
Section titled “1. Context and Problem Statement”AirCommerce microservices consume dynamic configurations managed by Configuration Service (service-configuration) and embedded via Configuration Util (util-configuration). Previously, the platform supported five configuration shapes: INPUT, SWITCH, DROPDOWN, MULTISELECT, and single-pair MAPPING.
When operations and engineering teams needed multi-column runtime matrices (such as fee tables, channel/cabin rule matrices, or multi-attribute feature overrides), storing raw JSON strings inside INPUT configurations introduced major defects:
- No Server-Side Schema Enforcement: Arbitrary JSON strings bypassed column definitions, required-cell checks, boolean formatting, and allowed option sets, allowing malformed configurations to persist into MongoDB and propagate over RabbitMQ.
- Repeated Client Parsing Boilerplate: Consuming microservices had to deserialize raw JSON strings manually and invent ad-hoc fallback handling for missing or malformed fields.
- Ambiguous Scalar vs. List Payloads: Without a structured cell contract, JSON numbers or booleans sent by callers or UI forms could fail strict string deserialization, while accidental nested objects (
{}) or arrays ([]) in scalar cells needed to fail fast.
2. Decision Drivers
Section titled “2. Decision Drivers”- Schema-Validated Matrix Persistence: Enforce column definitions, option constraints, required cells, and scalar-vs-list exclusivity server-side before committing MongoDB writes or emitting
ConfigurationChangedEvents. - Polymorphic Wire Compatibility: Extend the existing sealed
ConfigurationEntity,CreateConfigurationRequest,EditConfigurationRequest, andConfigurationResponsehierarchies withConfigurationType.TABLEwithout breaking the five existing configuration types. - Ergonomic Consumer SDK Contract: Support
@ConfigurationValue private List<TableRow>injection with typed cell accessors, live reload onUPDATED, and baseline fallback on startup miss orDELETED. - Controlled Complexity: Keep column types flat (
INPUT,SWITCH,DROPDOWN,MULTISELECT) and exclude nestedMAPPINGorTABLEcolumns.
3. Considered Options
Section titled “3. Considered Options”- Option 1: Store schema-less JSON strings in
ConfigurationType.INPUTand parse per consumer service. - Option 2: Introduce an untyped
List<Map<String, Object>>configuration type without column metadata or cell exclusivity. - Option 3 (Chosen): Introduce first-class
ConfigurationType.TABLEacrossservice-configurationandutil-configurationwith typedTableColumn/TableRow/TableCellcontracts, Jackson 3 lenient scalar coercion, and server-sideTableConfigurationValidator.
4. Decision Outcome
Section titled “4. Decision Outcome”We chose Option 3: adding ConfigurationType.TABLE end-to-end across service-configuration and util-configuration as a first-class polymorphic subtype (type: "TABLE").
4.1. Visual Architecture Slice
Section titled “4.1. Visual Architecture Slice”4.2. Implementation Mechanics
Section titled “4.2. Implementation Mechanics”1. Column & Cell Schema (service-configuration and util-configuration)
Section titled “1. Column & Cell Schema (service-configuration and util-configuration)”TableColumnType: Restricts columns toINPUT,SWITCH,DROPDOWN, andMULTISELECT(explicitly excluding nestedMAPPINGorTABLEtypes).TableColumn: Declareskey(^[a-zA-Z0-9\-_]*$),label,columnType,required, andselectableValues(required and non-empty forDROPDOWNandMULTISELECT).TableCellScalar/List Exclusivity: Each cell referencescolumnKeyand carries either scalarvalue(String) or listvalues(List<String>).MULTISELECTcolumns requirevaluesand forbidvalue;INPUT,SWITCH, andDROPDOWNcolumns requirevalueand forbidvalues.- Jackson 3 Lenient Scalar Coercion:
TableCell.LenientStringDeserializer(tools.jackson.databind.ValueDeserializer<String>) coercesVALUE_STRING,VALUE_NUMBER_INT,VALUE_NUMBER_FLOAT,VALUE_TRUE, andVALUE_FALSEviaparser.getValueAsString()(passingVALUE_NULLasnull), while explicitly rejecting non-scalarSTART_OBJECT({}) andSTART_ARRAY([]) tokens viacontext.handleUnexpectedToken(String.class, parser).
2. Server-Side Validation & Transactional Guarantees (service-configuration)
Section titled “2. Server-Side Validation & Transactional Guarantees (service-configuration)”ConfigurationService invokes TableConfigurationValidator.validate(columns, rows) on both CreateTableConfigurationRequest and EditTableConfigurationRequest (including PUT /configurations/bulk):
- Rejects empty/null column lists, blank/duplicate column keys, blank
selectableValuesentries, unknown or duplicate cellcolumnKeys within a row, non-booleanSWITCHstrings (case-insensitivetrue/false), out-of-rangeDROPDOWN/MULTISELECTselections, and missing or blank/empty required cells. - On
EditTableConfigurationRequest, omittingrows(null) clears existing rows onTableConfigurationEntityprior toModelMappermapping (MapperConfig) so stale rows are never retained. CustomGlobalExceptionHandlermapsInvalidTableConfigurationExceptionto HTTP400 Bad RequestwithResponseCode.INVALID_REQUEST. Bulk validation failures abort the MongoDB transaction and publish zero lifecycle events.
3. Client SDK Contract (util-configuration)
Section titled “3. Client SDK Contract (util-configuration)”@Componentpublic class FeeRuleService {
@ConfigurationValue("pricing.ancillary-fee-matrix") private List<TableRow> feeRules = List.of();
public BigDecimal feeForChannel(String channel) { return feeRules.stream() .filter(row -> row.getString("channel").filter(channel::equals).isPresent()) .filter(row -> row.getBoolean("active", false)) .findFirst() .map(row -> row.getBigDecimal("feeAmount", BigDecimal.ZERO)) .orElse(BigDecimal.ZERO); }}ConfigurationTypeUtils.determineConfigurationType(Field)inspects genericList<TableRow>fields and resolvesConfigurationType.TABLE.ConfigurationValueExtractor.extractValue(...)extractsTableConfigurationResponse#getRows()and throwsConfigurationExtractionExceptionif the remote type mismatchesTABLE.TableRowexposes defensive typed accessors:getString(columnKey)(Optional<String>),getBoolean(columnKey, defaultValue),getBigDecimal(columnKey, defaultValue), andgetList(columnKey)(List<String>), returning safe defaults when cells are missing or unparseable.ConfigurationValueInjector,ConfigurationChangedEventListener, andConfigurationActuatorEndpointpreserve default fallback on missing keys/DELETEDevents, live reload onUPDATEDevents, and exposeremoteType = "TABLE".
5. Pros and Cons of the Options
Section titled “5. Pros and Cons of the Options”Option 1: Raw JSON Strings in INPUT
Section titled “Option 1: Raw JSON Strings in INPUT”- Good: Zero schema changes to
service-configurationorutil-configuration. - Bad: No validation on write, silent consumer runtime failures, and duplicated parsing logic across services.
Option 2: Untyped List<Map<String, Object>>
Section titled “Option 2: Untyped List<Map<String, Object>>”- Good: Flexible ad-hoc row shapes without defining columns.
- Bad: Cannot enforce
DROPDOWN/MULTISELECToption sets,SWITCHbooleans, required columns, or reject nested{}/[]payloads consistently.
Option 3 (Chosen): First-Class ConfigurationType.TABLE
Section titled “Option 3 (Chosen): First-Class ConfigurationType.TABLE”- Good: Strong server-side validation, clean polymorphic REST contract, lenient scalar JSON coercion with strict non-scalar rejection, and zero-boilerplate
List<TableRow>injection. - Bad: Requires synchronized
TableCell/TableColumn/TableRowmodel definitions acrossservice-configurationandutil-configurationand a dedicated UI editor inapp-core-management.
6. Validation and Verification Strategy
Section titled “6. Validation and Verification Strategy”- Server-Side Verification (
service-configuration):mvn verifyvalidatesTableCellTest(Jackson 3 scalar coercion and{}/[]rejection),TableConfigurationValidatorTest(positive/negative schema, cell exclusivity, required fields),CustomGlobalExceptionHandlerTest(HTTP400/ResponseCode.INVALID_REQUEST),ConfigurationServiceTest(including clearing rows onnulledit), and integration tests for CRUD and bulk transaction rollback with zero emitted events. - Client SDK Verification (
util-configuration):mvn verifyvalidatesTableCellTest,TableConfigurationResponseTest(wire round-trip),TableRowTest(typed accessors and fallbacks),ConfigurationTypeUtilsTest,ConfigurationValueExtractorTest,ConfigurationValueInjectorTest,ConfigurationChangedEventListenerTest(UPDATEDreload /DELETEDrevert), andConfigurationActuatorEndpointTest(remoteType = "TABLE"). - Documentation Audit (
architecture-portal):npm run auditvalidates ontology integrity, ADR frontmatter schema, internal links, formatting, and full Astro static build.
7. Migration and Rollout Consequences
Section titled “7. Migration and Rollout Consequences”- Backward Compatibility: Existing
INPUT,SWITCH,DROPDOWN,MULTISELECT, andMAPPINGconfigurations, MongoDB indexes, RBAC roles, and REST paths remain unchanged. - Consumer Adoption: Microservices upgrade
util-configurationvia the centralized BOM (ADR 0005) and opt intoList<TableRow>per key without forced migrations. - Configuration UI Follow-Up: Interactive table editing in
app-core-management(configuration-ui) is tracked separately and remains out of scope for this backend and SDK rollout.
8. Links and Traceability
Section titled “8. Links and Traceability”- Configuration Service: Configuration Service
- Configuration API: Configuration API
- Configuration Util: Configuration Util
- Related ADRs: ADR 0001, ADR 0003, ADR 0005