Developer
News and Updates
Get Support
Sign in
Get Support
Sign in
DOCUMENTATION
Cloud
Data Center
Resources
Sign in
Sign in
DOCUMENTATION
Cloud
Data Center
Resources
Sign in
Last updated Nov 4, 2026

ADF Builder Java feature context

Technical Guide

The Feature Context is the mechanism in the core lib module for safely rolling out new parsing and modelling behaviours. It is completely separate from the Wiki Markup Conversion Feature Flags, which serve a similar purpose for the wiki module.

Overview

The Feature enum (in com.atlassian.adf.ctx) defines named feature flags for the core library. Each Feature is either enabled or disabled for the current thread. The enabled state is controlled via a thread-local Context object, which holds a FeatureProvider that answers feature enablement queries.

This design means that different threads can have different feature states simultaneously, and the state is automatically scoped to a single conversion call without leaking between calls.

Checking Whether a Feature Is Enabled

Inside library code, a feature is checked by calling Feature.XYZ.enabled():

1
2
3
4
if (Feature.PARSE_ENABLE_REPAIRS.enabled()) {
    // tolerate and silently repair certain malformed inputs
}

This reads the current thread's Context and asks its FeatureProvider whether the feature is enabled. If no Context has been established on the current thread, all features default to a state that is defined by the flag’s definition, which for most flags is disabled by default, but may express a dependency on another flag’s state or default to enabled for a flag that is deprecated anyway.

Enabling Features as a Caller

Callers enable features by wrapping their conversion call in a context:

1
2
3
4
5
6
7
8
9
10
11
// Enable a single feature
Context.withFeature(Feature.PARSE_ENABLE_REPAIRS).run(() -> {
    Doc doc = adf.parseDoc(json);
});

// Enable multiple features
FeatureSet features = FeatureSet.of(Feature.PARSE_ENABLE_REPAIRS, Feature.PARSE_REPAIR_EMPTY_TEXT);
Context.with(features, () -> {
    Doc doc = adf.parseDoc(json);
});

The context is restored to its previous state when the block exits, even if an exception is thrown.

Available Features

The following features are currently defined. Features marked as deprecated will be removed in a future major release. Most are no-ops because their behaviour has become unconditional; the plain-text features still affect the deprecated Node.toPlainText() and are replaced by settings on PlainTextConfig, which PlainTextTransformer uses instead.

FeatureDefaultDescription
PLAINTEXT_MENTION_USE_ID(deprecated)OffChanges how Node.toPlainText() renders mentions. When enabled, a mention with no display text uses the account ID instead of a generic fallback. Replaced by PlainTextConfig.MentionStyle.ID_WHEN_NAMELESS.
ALLOW_NESTED_LISTS_AS_FIRST_CHILD(deprecated)N/AOriginally controlled whether a nested list could appear as the first content item in a listItem. The rollout of ADF Change 94 (list indentation flexibility) is now complete and this is always permitted. This flag is a no-op.
PARSE_ENABLE_REPAIRSOffEnables tolerant parsing. When active, certain malformed inputs that would normally throw a parse exception are silently repaired instead. Enable with care — repairs may change the semantics of the input.
PARSE_REPAIR_EMPTY_TEXTFollows PARSE_ENABLE_REPAIRSWhen enabled, empty text nodes (which are technically invalid ADF) are silently dropped during parsing rather than causing an exception. This feature is automatically enabled whenever PARSE_ENABLE_REPAIRS is enabled.
PARSE_REPAIR_DOC_VERSIONFollows PARSE_ENABLE_REPAIRSWhen enabled, a doc node whose version is missing or is not a number is parsed as "version": 1 rather than causing an exception. A numeric version that is not supported, such as 2, is still rejected.
PARSE_REPAIR_MENTION_IDFollows PARSE_ENABLE_REPAIRSWhen enabled, a mention node whose id is missing or is not a string is parsed with "id": "unknown" rather than causing an exception. This is the placeholder that Jira uses for a user it cannot resolve. The node keeps its other attributes, such as text, so the repaired document has the same structure as the input.
PARSE_REPAIR_EMPTY_ATTRS_LISTFollows PARSE_ENABLE_REPAIRSWhen enabled, a node or mark whose attrs is an empty JSON array ([]) instead of an object is parsed as if it had no attributes. A non-empty array is still rejected.
PARSE_REPAIR_MEDIA_IDFollows PARSE_ENABLE_REPAIRSWhen enabled, a file or link media node whose id is missing, empty, or not a string is parsed with "id": "unknown". The repaired node does not refer to a real file, so it will not render as an image.
PARSE_REPAIR_MEDIA_URLFollows PARSE_ENABLE_REPAIRSWhen enabled, an external media node whose url is missing or not a string is parsed with "url": "".
PARSE_REPAIR_ROWSPANFollows PARSE_ENABLE_REPAIRSWhen enabled, a tableCell or tableHeader whose rowspan is zero or negative is parsed as if rowspan were absent, so the cell spans one row. A non-positive colspan is always treated this way.
PARSE_REPAIR_INVALID_MARKSFollows PARSE_ENABLE_REPAIRSWhen enabled, a mark that cannot be parsed or is not allowed where it appears is silently discarded, and the node keeps its other marks. This covers marks the node does not accept (such as link on a paragraph), unrecognized marks with no placeholder (such as unsupportedNodeAttribute), marks with wrongly typed attributes (such as a textColor whose color is not a string), and marks that the container does not allow on its content (such as formatting marks inside a codeBlock).
CONVERT_AS_MEDIA_INLINEOffAllows mediaInline nodes to be produced by format conversion modules. When disabled, converters fall back to mediaSingle.
FIX_COLOR_PARSINGOffExtends the CSS color formats accepted by the textColor mark parser to include 8-digit hex (#RRGGBBAA), rgba(), and percentage-based rgb() values, in addition to the standard 6-digit hex and named colors.
DATE_USE_EPOCH_MILLISOffChanges the format of date node timestamps from ISO-8601 strings to epoch milliseconds (as a number). Enable this if your downstream system expects the numeric format.
ENABLE_BLOCK_EMBED_CARD_URLS_PLAINTEXT(deprecated)OffWhen enabled, Node.toPlainText() renders blockCard and embedCard nodes as their URL instead of omitting them. Replaced by PlainTextConfig.CardStyle.URL.
CONVERT_TABLE_CELL_VALIGN(deprecated)N/AOriginally controlled whether the format conversion modules could produce the valign (vertical alignment) attribute on tableCell and tableHeader nodes. The rollout is now complete and HTML to ADF conversion always emits valign when the source specifies one. This flag is a no-op.

Feature Dependencies

Features can depend on each other. A dependent feature is automatically enabled whenever its parent is enabled, even if it was not explicitly included in the FeatureSet:

1
2
3
4
5
// PARSE_REPAIR_EMPTY_TEXT is automatically enabled by PARSE_ENABLE_REPAIRS
Context.withFeature(Feature.PARSE_ENABLE_REPAIRS).run(() -> {
    // Both PARSE_ENABLE_REPAIRS and PARSE_REPAIR_EMPTY_TEXT are active here
});

Dependencies are declared in the Feature enum via a BooleanSupplier constructor argument: PARSE_REPAIR_EMPTY_TEXT(PARSE_ENABLE_REPAIRS::enabled).

A dependent feature can still be set explicitly. For example, this enables every repair except the one for mention IDs:

1
2
3
4
5
6
7
8
FeatureSet features = FeatureSet.builder()
        .enable(Feature.PARSE_ENABLE_REPAIRS)
        .disable(Feature.PARSE_REPAIR_MENTION_ID)
        .build();
Context.withFeatures(features).run(() -> {
    // Missing doc versions are repaired, but a mention with no ID is still rejected
});

Advanced: Custom FeatureProviders

For advanced use cases — such as reading feature states from a remote feature flag service — you can supply a custom FeatureProvider to the context:

1
2
3
4
5
FeatureProvider myProvider = feature -> myFlagService.isEnabled(feature.name());
Context.withFeatureProvider(myProvider).run(() -> {
    Doc doc = adf.parseDoc(json);
});

FeatureProvider is a functional interface, so a lambda is sufficient for simple cases. FeatureSet implements FeatureProvider and can be used directly or composed with another provider via featureSet.withOverrides(baseProvider).

Application-Wide Default: GlobalDefaultFeatureProvider

The per-call context wrapping shown above is appropriate when only a subset of calls need different feature states. However, in a server application it is often preferable to wire the library to the application's feature flag service once at startup rather than at every call site. Use Context.GlobalDefaultFeatureProvider.set(...) for this:

1
2
3
4
5
6
7
8
9
// At application startup — wire the library to your feature flag service
Context.GlobalDefaultFeatureProvider.set(
    feature -> myFlagService.isEnabled(feature.name())
);

// From this point on, every call anywhere in the process benefits from the
// registered provider, without any per-call context wrapping.
Doc doc = adf.parseDoc(json);

The registered provider acts as the process-wide default. It applies on any thread that has not established a more specific per-thread context. Per-thread overrides via Context.withFeature() or Context.withFeatures() always take precedence over the global default — the two mechanisms compose cleanly.

To restore the built-in defaults, pass null:

1
2
Context.GlobalDefaultFeatureProvider.set(null); // restore built-in defaults

Thread safety: GlobalDefaultFeatureProvider.set() updates a volatile field and is safe to call from any thread. However, it affects all threads in the process immediately. It should normally only be called once, at application startup, before any conversions have begun. The expected pattern is to define a @Singleton component that installs itself as the default using @PostConstruct and optionally restores the null value in @PreDestroy.

Relationship to Wiki Markup Feature Flags

The Feature context described on this page is only for the core lib module (ADF model, parsing, and validation). The wiki transformer module has a completely separate feature flag mechanism based on FeatureFlag and FeatureFlagProvider objects.

See Conversion Feature Flags for documentation of the wiki module's flags.

Do not confuse the two systems — they are independent and have different APIs.

Rate this page: