Skip to content

Conversation

@philsttr
Copy link
Collaborator

@philsttr philsttr commented Oct 19, 2025

Migrate from Jackson 2 to Jackson 3.

See the Jackson 3 Migration guide for more background on the changes that were required.

Decorators

In Jackson 3.0, ObjectMapper and JsonFactory are now immutable (previously, they were mutable).

An ObjectMapper is now configured and created via a MapperBuilder. In addition, Jackson now has subclasses of ObjectMapper and MapperBuilder specific to different data formats (e.g. JsonMapper and JsonMapper.Builder for json, and YAMLMapper and YAMLMapper.Builder for yaml).

A JsonFactory is now configured and created via a JsonFactoryBuilder. In addition, Jackson now has a higher level TokenStreamFactory and TSFBuilder as a superclass to support different data formats (e.g. YAMLFactory and YAMLFactoryBuilder).

Previously, logstash-logback-encoder had the following decorators:

  • JsonFactoryDecorator
    • decorated a JsonFactory (and ObjectMapper indirectly via jsonFactory.getCodec())
    • registered via <jsonFactoryDecorator class="SomeJsonFactoryDecorator"/>
  • JsonGeneratorDecorator
    • decorated a JsonGenerator
    • registered via <jsonGeneratorDecorator class="SomeJsonGeneratorDecorator"/>

To support the changes in Jackson 3.0, JsonFactoryDecorator and all its implementations were refactored.

Now, logstash-logback-encoder has the following decorators:

  • MapperBuilderDecorator, which decorates a MapperBuilder (or subclass),
  • TokenStreamFactoryBuilderDecorator, which decorates a TSFBuilder (or subclass), and
  • JsonGeneratorDecorator, which decorates a JsonGenerator. This is generally to wrap a JsonGenerator and delegate to it, since JsonGenerator is immutable.

All decorators are now registered via <decorator class="SomeDecorator"/>.

Replacements for previous decorator implementations provided by logstash-logback-encoder are as follows:

Old New
JsonFactoryDecorator MapperBuilderDecorator or TokenStreamFactoryBuilderDecorator
CompositeJsonFactoryDecorator CompositeMapperBuilderDecorator or CompositeTokenStreamFactoryBuilderDecorator
CharacterEscapesJsonFactoryDecorator CharacterEscapesDecorator
EscapeNonAsciiJsonFactoryDecorator see Feature Decorators section
CborJsonFactoryDecorator see Data Format section
YamlJsonFactoryDecorator see Data Format section
SmileJsonFactoryDecorator see Data Format section
JsonGeneratorDecorator JsonGeneratorDecorator
PrettyPrintingJsonGeneratorDecorator PrettyPrintingDecorator
MaskingJsonGeneratorDecorator MaskingJsonGeneratorDecorator (no change)
FeatureJsonFactoryDecorator See Feature Decorators section
FeatureJsonGeneratorDecorator See Feature Decorators section
CborFeatureJsonGeneratorDecorator CborWriteFeatureDecorator (see Feature Decorators section)
SmileFeatureJsonGeneratorDecorator SmileWriteFeatureDecorator (see Feature Decorators section)
YamlFeatureJsonGeneratorDecorator YamlWriteFeatureDecorator (see Feature Decorators section)
NullJsonFactoryDecorator removed
NullJsonGeneratorDecorator removed

Feature Decorators

Feature enums were refactored drastically in Jackson 3.0.
As a result, the decorators used to configure features have changed.
The following table shows which feature decorator to use to configure each Jackson feature type.

Jackson Feature Enum Feature Decorator
TokenStreamFactory.Feature net.logstash.logback.decorate.TokenStreamFactoryFeatureDecorator
MapperFeature net.logstash.logback.decorate.MapperFeatureDecorator
SerializationFeature net.logstash.logback.decorate.SerializationFeatureDecorator
StreamWriteFeature net.logstash.logback.decorate.StreamWriteFeatureDecorator
JsonNodeFeature net.logstash.logback.decorate.JsonNodeFeatureDecorator
EnumFeature net.logstash.logback.decorate.EnumFeatureDecorator
DateTimeFeature net.logstash.logback.decorate.DateTimeFeatureDecorator
JsonWriteFeature net.logstash.logback.decorate.json.JsonWriteFeatureDecorator
SmileWriteFeature net.logstash.logback.decorate.smile.SmileWriteFeatureDecorator
YAMLWriteFeature net.logstash.logback.decorate.yaml.YamlWriteFeatureDecorator
CBORWriteFeature net.logstash.logback.decorate.cbor.CborWriteFeatureDecorator

The following old decorators were replaced by one or more of the above feature decorators
(depending on where the feature moved in Jackson 3.0):

  • FeatureJsonFactoryDecorator
  • FeatureJsonGeneratorDecorator
  • CborFeatureJsonGeneratorDecorator
  • SmileFeatureJsonGeneratorDecorator
  • YamlFeatureJsonGeneratorDecorator
  • EscapeNonAsciiJsonFactoryDecorator

Data Format

Previously, non-JSON data formats were enabled via a JsonFactoryDecorator. For example:

  <jsonFactoryDecorator class="net.logstash.logback.decorate.smile.SmileJsonFactoryDecorator"/>

Now, the data format is controlled by a DataFormatFactory, with built-in support provided for json (the default), yaml, cbor, and smile.
For example:

  <dataFormat>smile</dataFormat>

Or:

 <dataFormatFactory class="net.logstash.logback.dataformat.smile.SmileDataFormatFactory"/>

Also, the feature decorator class names for the configuring data format features has changed
(see also the Feature Decorators section):

Old New
SmileFeatureJsonGeneratorDecorator SmileWriteFeatureDecorator
YamlFeatureJsonGeneratorDecorator YamlWriteFeatureDecorator
CborFeatureJsonGeneratorDecorator CborWriteFeatureDecorator

Maskers

In Jackson 3.0, JsonStreamContext was replaced with TokenStreamContext.

Therefore, references to JsonStreamContext in logstash-logback-encoder's FieldMasker and ValueMasker were changed to TokenStreamContext.

JsonFactoryAware

Previously, a JsonProvider could implement JsonFactoryAware to be injected with the JsonFactory.

Now, JsonFactoryAware has been removed.
Instead, a JsonProvider can implement ObjectMapperAware to be injected with the ObjectMapper.

This change was made because in Jackson 3.0:

  • JsonFactory is now specific to json (i.e. other data formats use subclasses of TokenStreamFactory),
  • An ObjectMapper can no longer be retrieved from a JsonFactory, but a TokenStreamFactory can be retrieved from an ObjectMapper.

@philsttr philsttr added type/enhancement warn/api-change Breaking change with compilation or xml configuration errors labels Oct 19, 2025
@philsttr philsttr merged commit c970c48 into main Oct 19, 2025
8 checks passed
@philsttr philsttr deleted the jackson_3.0 branch October 19, 2025 00:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type/enhancement warn/api-change Breaking change with compilation or xml configuration errors

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants