|
1 | 1 | package com.revengemission.plugins.mybatis; |
2 | 2 |
|
3 | | -import com.fasterxml.jackson.databind.JsonNode; |
4 | 3 | import org.mybatis.generator.api.IntrospectedColumn; |
5 | 4 | import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; |
6 | 5 | import org.mybatis.generator.internal.types.JavaTypeResolverDefaultImpl; |
@@ -47,13 +46,31 @@ public void addConfigurationProperties(Properties properties) { |
47 | 46 | boolean forceOtherToJson = StringUtility.isTrue(properties.getProperty("forceOtherToJson")); |
48 | 47 | if (forceOtherToJson) { |
49 | 48 | 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 | + } |
51 | 54 | } |
52 | 55 | // mysql json |
53 | 56 | boolean forceLongVarcharToJson = StringUtility.isTrue(properties.getProperty("forceLongVarcharToJson")); |
54 | 57 | if (forceLongVarcharToJson) { |
55 | 58 | 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; |
57 | 74 | } |
58 | 75 | } |
59 | 76 | } |
0 commit comments