Skip to content

Commit e9d3089

Browse files
MartijnVissertzulitai
authored andcommitted
[FLINK-33191][Connector/Kafka] Remove dependency on Flink Shaded
1 parent 26ab532 commit e9d3089

File tree

5 files changed

+78
-20
lines changed

5 files changed

+78
-20
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.flink.connector.kafka.util;
19+
20+
import com.fasterxml.jackson.core.JsonFactory;
21+
import com.fasterxml.jackson.databind.ObjectMapper;
22+
import com.fasterxml.jackson.databind.SerializationFeature;
23+
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
24+
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
25+
26+
/** Factory for Jackson mappers. */
27+
public final class JacksonMapperFactory {
28+
29+
public static ObjectMapper createObjectMapper() {
30+
final ObjectMapper objectMapper = new ObjectMapper();
31+
registerModules(objectMapper);
32+
return objectMapper;
33+
}
34+
35+
public static ObjectMapper createObjectMapper(JsonFactory jsonFactory) {
36+
final ObjectMapper objectMapper = new ObjectMapper(jsonFactory);
37+
registerModules(objectMapper);
38+
return objectMapper;
39+
}
40+
41+
private static void registerModules(ObjectMapper mapper) {
42+
mapper.registerModule(new JavaTimeModule())
43+
.registerModule(new Jdk8Module().configureAbsentsAsNulls(true))
44+
.disable(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS)
45+
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
46+
}
47+
48+
private JacksonMapperFactory() {}
49+
}

flink-connector-kafka/src/main/java/org/apache/flink/streaming/util/serialization/JSONKeyValueDeserializationSchema.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,12 @@
2020
import org.apache.flink.annotation.PublicEvolving;
2121
import org.apache.flink.api.common.serialization.DeserializationSchema;
2222
import org.apache.flink.api.common.typeinfo.TypeInformation;
23+
import org.apache.flink.connector.kafka.util.JacksonMapperFactory;
2324
import org.apache.flink.streaming.connectors.kafka.KafkaDeserializationSchema;
24-
import org.apache.flink.util.jackson.JacksonMapperFactory;
25-
26-
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode;
27-
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper;
28-
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode;
2925

26+
import com.fasterxml.jackson.databind.JsonNode;
27+
import com.fasterxml.jackson.databind.ObjectMapper;
28+
import com.fasterxml.jackson.databind.node.ObjectNode;
3029
import org.apache.kafka.clients.consumer.ConsumerRecord;
3130

3231
import static org.apache.flink.api.java.typeutils.TypeExtractor.getForClass;

flink-connector-kafka/src/test/java/org/apache/flink/connector/kafka/source/reader/deserializer/KafkaRecordDeserializationSchemaTest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,16 @@
1818

1919
package org.apache.flink.connector.kafka.source.reader.deserializer;
2020

21+
import org.apache.flink.connector.kafka.util.JacksonMapperFactory;
2122
import org.apache.flink.connector.testutils.formats.DummyInitializationContext;
2223
import org.apache.flink.connector.testutils.source.deserialization.TestingDeserializationContext;
2324
import org.apache.flink.formats.json.JsonDeserializationSchema;
2425
import org.apache.flink.streaming.util.serialization.JSONKeyValueDeserializationSchema;
2526
import org.apache.flink.util.Collector;
26-
import org.apache.flink.util.jackson.JacksonMapperFactory;
27-
28-
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException;
29-
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper;
30-
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode;
3127

28+
import com.fasterxml.jackson.core.JsonProcessingException;
29+
import com.fasterxml.jackson.databind.ObjectMapper;
30+
import com.fasterxml.jackson.databind.node.ObjectNode;
3231
import org.apache.kafka.clients.consumer.ConsumerRecord;
3332
import org.apache.kafka.common.Configurable;
3433
import org.apache.kafka.common.serialization.StringDeserializer;

flink-connector-kafka/src/test/java/org/apache/flink/streaming/connectors/kafka/JSONKeyValueDeserializationSchemaTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@
1717

1818
package org.apache.flink.streaming.connectors.kafka;
1919

20+
import org.apache.flink.connector.kafka.util.JacksonMapperFactory;
2021
import org.apache.flink.connector.testutils.formats.DummyInitializationContext;
2122
import org.apache.flink.streaming.util.serialization.JSONKeyValueDeserializationSchema;
22-
import org.apache.flink.util.jackson.JacksonMapperFactory;
23-
24-
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper;
25-
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode;
2623

24+
import com.fasterxml.jackson.databind.ObjectMapper;
25+
import com.fasterxml.jackson.databind.node.ObjectNode;
2726
import org.apache.kafka.clients.consumer.ConsumerRecord;
2827
import org.junit.Test;
2928

pom.xml

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ under the License.
5454
<zookeeper.version>3.5.9</zookeeper.version>
5555
<confluent.version>7.2.2</confluent.version>
5656

57-
<jackson-bom.version>2.13.4.20221013</jackson-bom.version>
57+
<jackson-bom.version>2.15.2</jackson-bom.version>
5858
<junit4.version>4.13.2</junit4.version>
5959
<junit5.version>5.9.1</junit5.version>
6060
<assertj.version>3.23.1</assertj.version>
@@ -80,13 +80,25 @@ under the License.
8080
</properties>
8181

8282
<dependencies>
83+
<!-- Root dependencies for all projects -->
8384
<dependency>
84-
<groupId>org.apache.flink</groupId>
85-
<artifactId>flink-shaded-jackson</artifactId>
86-
<version>2.13.4-16.1</version>
85+
<groupId>com.fasterxml.jackson.core</groupId>
86+
<artifactId>jackson-core</artifactId>
87+
</dependency>
88+
<dependency>
89+
<groupId>com.fasterxml.jackson.core</groupId>
90+
<artifactId>jackson-databind</artifactId>
91+
</dependency>
92+
<dependency>
93+
<!-- Java 8 Date/time -->
94+
<groupId>com.fasterxml.jackson.datatype</groupId>
95+
<artifactId>jackson-datatype-jsr310</artifactId>
96+
</dependency>
97+
<dependency>
98+
<!-- Java 8 Datatypes -->
99+
<groupId>com.fasterxml.jackson.datatype</groupId>
100+
<artifactId>jackson-datatype-jdk8</artifactId>
87101
</dependency>
88-
89-
<!-- Root dependencies for all projects -->
90102

91103
<!-- Logging API -->
92104
<dependency>

0 commit comments

Comments
 (0)