Documentation, examples and further information of the ta4j project
This project is maintained by ta4j Organization
Status: Draft Target: ta4j-core (serialization) Feature branch: codex/serialization-versioned-spec
Status: still draft/proposed.
Current baseline:
ComponentSerialization, RuleSerialization, and StrategySerialization.toVersionedJson(...) / fromVersionedJson(...) API yet.ComponentSerialization for descriptor stability, but not as a full versioned envelope contract.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.
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.
toJson/fromJson behavior.ComponentDescriptor JSON describing a rule/indicator/strategy.1) New versioned APIs:
ComponentSerialization.toVersionedJson(descriptor) -> v1 envelope JSON.ComponentSerialization.parseVersioned(json) -> {version, descriptor}.StrategySerialization.toVersionedJson(strategy) / fromVersionedJson(series, json).RuleSerialization.toVersionedJson(rule) / fromVersionedJson(series, json).2) Versioned format:
version.3) Canonicalization:
Num and numeric arrays.4) Legacy support:
children, baseIndicators).5) Errors:
toJson output (no breaking change).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:
version (int, required)payload (ComponentDescriptor, required)Optional: kind (strategy |
rule | indicator) for debugging; ignored during parsing |
Canonical JSON is defined as:
type, label, parameters, then rules/components.__ sort after non-metadata keys.Num string values normalized to the
same representation already used in RuleSerializationRoundTripTestSupport).[entry, exit] order.Implementation approach:
ComponentDescriptor (sorted parameters + stable components).ComponentSerialization adapter.Additive APIs:
ComponentSerialization.toVersionedJson(ComponentDescriptor descriptor) (v1)ComponentSerialization.parseVersioned(String json) -> VersionedDescriptor (new value object)StrategySerialization.toVersionedJson(Strategy strategy)StrategySerialization.fromVersionedJson(BarSeries series, String json)RuleSerialization.toVersionedJson(Rule rule)RuleSerialization.fromVersionedJson(BarSeries series, String json)Keep existing:
ComponentSerialization.toJson(...)StrategySerialization.toJson(...)StrategySerialization.fromJson(...)RuleSerialization.describe(...) / RuleSerialization.fromDescriptor(...)Parsing rules:
version and payload, parse as envelope.Migration:
ComponentSerialization.parse(...).version -> IllegalArgumentException("Unsupported serialization version: X")payload -> IllegalArgumentException("Missing payload for versioned serialization")IllegalArgumentException("Invalid payload: ...")Update ta4j README serialization section to mention:
Add/extend ta4j-core tests:
ComponentSerializationTest:
parseVersioned() handles v1 envelopeRuleSerializationTest:
StrategySerializationTest:
Use RuleSerializationRoundTripTestSupport to normalize expected descriptors where appropriate.
Phase 1 (Additive):
Phase 2 (Optional):
kind field for debugging?Num.toString()?org.ta4j.core.serialization.ComponentSerialization, RuleSerialization, and StrategySerialization.toVersionedJson/fromVersionedJson APIs in current ta4j-core history up to commit 6cce8809.