Skip to content

Commit 90bbb74

Browse files
committed
support jackson3
1 parent 0bea375 commit 90bbb74

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

pom.xml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>com.revengemission.plugins</groupId>
66
<artifactId>mybatis-plugins</artifactId>
7-
<version>2.1.3</version>
7+
<version>2.2.0</version>
88
<packaging>jar</packaging>
99
<name>${project.artifactId}</name>
1010
<description>MyBatis Generator plugins</description>
@@ -37,7 +37,14 @@
3737
<dependency>
3838
<groupId>com.fasterxml.jackson.core</groupId>
3939
<artifactId>jackson-databind</artifactId>
40-
<version>2.20.0</version>
40+
<version>2.20.1</version>
41+
<scope>provided</scope>
42+
</dependency>
43+
44+
<dependency>
45+
<groupId>tools.jackson.core</groupId>
46+
<artifactId>jackson-databind</artifactId>
47+
<version>3.0.2</version>
4148
<scope>provided</scope>
4249
</dependency>
4350

@@ -56,7 +63,7 @@
5663
<dependency>
5764
<groupId>com.mysql</groupId>
5865
<artifactId>mysql-connector-j</artifactId>
59-
<version>9.4.0</version>
66+
<version>9.5.0</version>
6067
<scope>test</scope>
6168
</dependency>
6269
<dependency>
@@ -214,10 +221,11 @@
214221
<plugin>
215222
<groupId>org.sonatype.central</groupId>
216223
<artifactId>central-publishing-maven-plugin</artifactId>
217-
<version>0.5.0</version>
224+
<version>0.9.0</version>
218225
<extensions>true</extensions>
219226
<configuration>
220227
<publishingServerId>central-releases</publishingServerId>
228+
<autoPublish>true</autoPublish>
221229
</configuration>
222230
</plugin>
223231
</plugins>

src/main/java/com/revengemission/plugins/mybatis/CustomTypeResolver.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.revengemission.plugins.mybatis;
22

3-
import com.fasterxml.jackson.databind.JsonNode;
43
import org.mybatis.generator.api.IntrospectedColumn;
54
import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;
65
import org.mybatis.generator.internal.types.JavaTypeResolverDefaultImpl;
@@ -47,13 +46,31 @@ public void addConfigurationProperties(Properties properties) {
4746
boolean forceOtherToJson = StringUtility.isTrue(properties.getProperty("forceOtherToJson"));
4847
if (forceOtherToJson) {
4948
log.info("===forceOtherToJson=true");
50-
this.typeMap.put(Types.OTHER, new JdbcTypeInformation(JDBCType.OTHER.name(), new FullyQualifiedJavaType(JsonNode.class.getName())));
49+
if (isJackson3()) {
50+
this.typeMap.put(Types.OTHER, new JdbcTypeInformation(JDBCType.OTHER.name(), new FullyQualifiedJavaType(tools.jackson.databind.JsonNode.class.getName())));
51+
} else {
52+
this.typeMap.put(Types.OTHER, new JdbcTypeInformation(JDBCType.OTHER.name(), new FullyQualifiedJavaType(com.fasterxml.jackson.databind.JsonNode.class.getName())));
53+
}
5154
}
5255
// mysql json
5356
boolean forceLongVarcharToJson = StringUtility.isTrue(properties.getProperty("forceLongVarcharToJson"));
5457
if (forceLongVarcharToJson) {
5558
log.info("===forceLongVarcharToJson=true");
56-
this.typeMap.put(Types.LONGVARCHAR, new JdbcTypeInformation(JDBCType.OTHER.name(), new FullyQualifiedJavaType(JsonNode.class.getName())));
59+
if (isJackson3()) {
60+
this.typeMap.put(Types.LONGVARCHAR, new JdbcTypeInformation(JDBCType.OTHER.name(), new FullyQualifiedJavaType(tools.jackson.databind.JsonNode.class.getName())));
61+
} else {
62+
this.typeMap.put(Types.LONGVARCHAR, new JdbcTypeInformation(JDBCType.OTHER.name(), new FullyQualifiedJavaType(com.fasterxml.jackson.databind.JsonNode.class.getName())));
63+
}
64+
}
65+
}
66+
67+
boolean isJackson3() {
68+
try {
69+
// Try to load a Jackson 3 specific class
70+
Class.forName("tools.jackson.databind.ObjectMapper");
71+
return true;
72+
} catch (ClassNotFoundException e) {
73+
return false;
5774
}
5875
}
5976
}

0 commit comments

Comments
 (0)