Ta4j Wiki

Documentation, examples and further information of the ta4j project

View the Wiki On GitHub

This project is maintained by ta4j Organization

Ta4j Serialization Versioning + Canonical JSON Spec

Status: Draft Target: ta4j-core (serialization) Feature branch: codex/serialization-versioned-spec

Status Snapshot (2026-03-06)

Status: still draft/proposed.

Current baseline:

Summary

Introduce a versioned, canonical JSON format for ta4j rule/strategy (and indicator) serialization. The change is additive: new versioned APIs coexist with existing JSON payloads, and legacy (versionless) payloads remain readable. Canonicalization guarantees deterministic output for persisted payloads and strategy identity comparisons.

Background

Ta4j already provides StrategySerialization and RuleSerialization, and CF consumes the JSON for persistence and resumption. However:

This spec makes the JSON safe for long-lived persistence and deterministic comparisons while keeping the current API usable.

Goals

Non-Goals

Definitions

Requirements

Functional

1) New versioned APIs:

2) Versioned format:

3) Canonicalization:

4) Legacy support:

5) Errors:

Non-Functional

Proposed Design

1) Versioned Envelope

Use an outer wrapper rather than adding fields to ComponentDescriptor.

Example (v1):

{
  "version": 1,
  "payload": {
    "type": "BaseStrategy",
    "label": "MyStrategy",
    "parameters": { "unstableBars": 3 },
    "rules": [
      { "type": "OverIndicatorRule", "components": [ ... ] },
      { "type": "CrossedDownIndicatorRule", "components": [ ... ] }
    ]
  }
}

Envelope fields:

2) Canonicalization Rules (v1+)

Canonical JSON is defined as:

Implementation approach:

3) API Surface

Additive APIs:

Keep existing:

4) Backward Compatibility

Parsing rules:

Migration:

5) Error Handling

6) Documentation

Update ta4j README serialization section to mention:

Tests

Add/extend ta4j-core tests:

Use RuleSerializationRoundTripTestSupport to normalize expected descriptors where appropriate.

Rollout Plan

Phase 1 (Additive):

Phase 2 (Optional):

Risks and Mitigations

Open Questions

Acceptance Criteria

Rationale Notes (2026-03-06)