Skip to content

Upgrade Jackson from 2.x to 3.0.0-rc4 #3701

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion log4j-config-jackson/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<groupId>tools.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,12 @@
*/
package org.apache.logging.log4j.config.jackson;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.AbstractConfiguration;
Expand All @@ -38,6 +32,10 @@
import org.apache.logging.log4j.core.config.status.StatusConfiguration;
import org.apache.logging.log4j.plugins.Node;
import org.apache.logging.log4j.plugins.model.PluginType;
import tools.jackson.databind.JsonNode;
import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.node.JsonNodeFactory;
import tools.jackson.databind.node.ObjectNode;

/**
* Base class for all Jackson-based configurations.
Expand Down Expand Up @@ -116,10 +114,8 @@ protected abstract Configuration createConfiguration(

@Override
public void setup() {
final Iterator<Entry<String, JsonNode>> iter = root.fields();
final List<Node> children = rootNode.getChildren();
while (iter.hasNext()) {
final Map.Entry<String, JsonNode> entry = iter.next();
for (Map.Entry<String, JsonNode> entry : root.properties()) {
final JsonNode n = entry.getValue();
if (n.isObject()) {
LOGGER.debug("Processing node for object {}", entry.getKey());
Expand Down Expand Up @@ -154,10 +150,8 @@ private Node constructNode(final String name, final Node parent, final JsonNode
final PluginType<?> type = corePlugins.get(getType(jsonNode, name));
final Node node = new Node(parent, name, type);
processAttributes(node, jsonNode);
final Iterator<Map.Entry<String, JsonNode>> iter = jsonNode.fields();
final List<Node> children = node.getChildren();
while (iter.hasNext()) {
final Map.Entry<String, JsonNode> entry = iter.next();
for (Map.Entry<String, JsonNode> entry : jsonNode.properties()) {
final JsonNode n = entry.getValue();
if (n.isArray() || n.isObject()) {
if (type == null) {
Expand Down Expand Up @@ -195,9 +189,7 @@ private Node constructNode(final String name, final Node parent, final JsonNode
}

private String getType(final JsonNode node, final String name) {
final Iterator<Map.Entry<String, JsonNode>> iter = node.fields();
while (iter.hasNext()) {
final Map.Entry<String, JsonNode> entry = iter.next();
for (Map.Entry<String, JsonNode> entry : node.properties()) {
if ("type".equalsIgnoreCase(entry.getKey())) {
final JsonNode n = entry.getValue();
if (n.isValueNode()) {
Expand All @@ -210,9 +202,7 @@ private String getType(final JsonNode node, final String name) {

private void processAttributes(final Node parent, final JsonNode node) {
final Map<String, String> attrs = parent.getAttributes();
final Iterator<Map.Entry<String, JsonNode>> iter = node.fields();
while (iter.hasNext()) {
final Map.Entry<String, JsonNode> entry = iter.next();
for (Map.Entry<String, JsonNode> entry : node.properties()) {
if (!"type".equalsIgnoreCase(entry.getKey())) {
final JsonNode n = entry.getValue();
if (n.isValueNode()) {
Expand Down
2 changes: 1 addition & 1 deletion log4j-config-properties/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<groupId>tools.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-properties</artifactId>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
*/
package org.apache.logging.log4j.config.properties;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.javaprop.JavaPropsMapper;
import org.apache.logging.log4j.config.jackson.AbstractJacksonConfiguration;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.ConfigurationSource;
import tools.jackson.databind.ObjectMapper;
import tools.jackson.dataformat.javaprop.JavaPropsMapper;

/**
* Creates a Node hierarchy from a properties file.
Expand All @@ -41,7 +40,6 @@ protected Configuration createConfiguration(

protected ObjectMapper getObjectMapper() {
return JavaPropsMapper.builder()
.configure(JsonParser.Feature.ALLOW_COMMENTS, true)
.nodeFactory(SortingNodeFactory.INSTANCE)
.build();
}
Expand Down
2 changes: 1 addition & 1 deletion log4j-config-yaml/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<groupId>tools.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
*/
package org.apache.logging.log4j.config.yaml;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
import org.apache.logging.log4j.config.jackson.AbstractJacksonConfiguration;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.ConfigurationSource;
import tools.jackson.databind.ObjectMapper;
import tools.jackson.dataformat.yaml.YAMLMapper;

/**
* Creates a Node hierarchy from a YAML file.
Expand All @@ -41,8 +40,6 @@ protected Configuration createConfiguration(

@Override
protected ObjectMapper getObjectMapper() {
return YAMLMapper.builder()
.configure(JsonParser.Feature.ALLOW_COMMENTS, true)
.build();
return YAMLMapper.builder().build();
}
}
16 changes: 12 additions & 4 deletions log4j-core-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -156,28 +156,28 @@

<!-- Required for JSON support -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<groupId>tools.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<optional>true</optional>
</dependency>

<!-- Required for JSON support -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<groupId>tools.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<optional>true</optional>
</dependency>

<!-- Required for XML layout and receiver support -->
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<groupId>tools.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<optional>true</optional>
</dependency>

<!-- Required for YAML support (including JSON requirements) -->
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<groupId>tools.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<optional>true</optional>
</dependency>
Expand Down Expand Up @@ -315,6 +315,14 @@
<scope>test</scope>
</dependency>

<!-- Needed by wiremock for testing -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson2.test.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.xmlunit</groupId>
<artifactId>xmlunit-core</artifactId>
Expand Down
9 changes: 2 additions & 7 deletions log4j-docker/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@
<!--
~ OSGi and JPMS options
-->
<bnd-extra-module-options>
<!-- Non detected module names -->
com.fasterxml.jackson.core;substitute="jackson-core",
com.fasterxml.jackson.databind;substitute="jackson-databind"
</bnd-extra-module-options>
<Fragment-Host>org.apache.logging.log4j.core</Fragment-Host>
</properties>

Expand All @@ -59,11 +54,11 @@
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<groupId>tools.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<groupId>tools.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
*/
package org.apache.logging.log4j.docker;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.net.URI;
import java.net.URL;
Expand All @@ -33,6 +31,8 @@
import org.apache.logging.log4j.kit.env.PropertyEnvironment;
import org.apache.logging.log4j.plugins.Plugin;
import org.apache.logging.log4j.status.StatusLogger;
import tools.jackson.core.type.TypeReference;
import tools.jackson.databind.ObjectMapper;

/**
* Looks up keys for a Docker container.
Expand Down
2 changes: 2 additions & 0 deletions log4j-layout-template-json-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,11 @@
<scope>test</scope>
</dependency>

<!-- Needed by elasticsearch-java for testing -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson2.test.version}</version>
<scope>test</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
package org.apache.logging.log4j.layout.template.json;

import com.fasterxml.jackson.databind.ObjectMapper;
import tools.jackson.databind.ObjectMapper;

public final class JacksonFixture {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.MappingIterator;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.ByteArrayOutputStream;
import java.io.EOFException;
import java.io.IOException;
Expand Down Expand Up @@ -83,6 +80,9 @@
import org.apache.logging.log4j.plugins.Plugin;
import org.apache.logging.log4j.plugins.PluginFactory;
import org.junit.jupiter.api.Test;
import tools.jackson.databind.JsonNode;
import tools.jackson.databind.MappingIterator;
import tools.jackson.databind.ObjectMapper;

@SuppressWarnings("DoubleBraceInitialization")
class JsonTemplateLayoutTest {
Expand Down
7 changes: 5 additions & 2 deletions log4j-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,10 @@
<hamcrest.version>3.0</hamcrest.version>
<HdrHistogram.version>2.2.2</HdrHistogram.version>
<hsqldb.version>2.7.4</hsqldb.version>
<jackson-bom.version>2.19.0</jackson-bom.version>
<!-- wiremock and elasticsearch-java libraries used for testing require Jackson 2 -->
<!-- The log4j project is using Jackson 3. -->
<jackson2.test.version>2.19.0</jackson2.test.version>
<jackson-bom.version>3.0.0-rc5</jackson-bom.version>
<javax-jms.version>2.0.1</javax-jms.version>
<java-allocation-instrumenter.version>3.3.4</java-allocation-instrumenter.version>
<jctools.version>4.0.5</jctools.version>
Expand Down Expand Up @@ -200,7 +203,7 @@
</dependency>

<dependency>
<groupId>com.fasterxml.jackson</groupId>
<groupId>tools.jackson</groupId>
<artifactId>jackson-bom</artifactId>
<version>${jackson-bom.version}</version>
<type>pom</type>
Expand Down
4 changes: 2 additions & 2 deletions log4j-perf-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,13 @@
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<groupId>tools.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<groupId>tools.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<optional>true</optional>
</dependency>
Expand Down
Loading