Skip to content

Commit 8664f15

Browse files
committed
Full fix of #132 for 2.13
1 parent 4b92a98 commit 8664f15

File tree

2 files changed

+129
-39
lines changed

2 files changed

+129
-39
lines changed

mrbean/dependency-reduced-pom.xml

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<parent>
4+
<artifactId>jackson-modules-base</artifactId>
5+
<groupId>com.fasterxml.jackson.module</groupId>
6+
<version>3.0.0-SNAPSHOT</version>
7+
</parent>
8+
<modelVersion>4.0.0</modelVersion>
9+
<artifactId>foobar-shaded</artifactId>
10+
<packaging>bundle</packaging>
11+
<name>Jackson module: Mr Bean</name>
12+
<description>Functionality for implementing interfaces and abstract types
13+
dynamically ("bean materialization"), integrated with Jackson (although usable externally as well)</description>
14+
<url>https://github.com/FasterXML/jackson-modules-base</url>
15+
<build>
16+
<plugins>
17+
<plugin>
18+
<groupId>com.google.code.maven-replacer-plugin</groupId>
19+
<artifactId>replacer</artifactId>
20+
</plugin>
21+
<plugin>
22+
<artifactId>maven-shade-plugin</artifactId>
23+
<executions>
24+
<execution>
25+
<phase>package</phase>
26+
<goals>
27+
<goal>shade</goal>
28+
</goals>
29+
<configuration>
30+
<shadedArtifactAttached>false</shadedArtifactAttached>
31+
<shadedArtifactId>foobar-shaded</shadedArtifactId>
32+
<artifactSet>
33+
<includes>
34+
<include>net.bytebuddy:byte-buddy</include>
35+
</includes>
36+
</artifactSet>
37+
<relocations>
38+
<relocation>
39+
<pattern>net.bytebuddy</pattern>
40+
<shadedPattern>com.fasterxml.jackson.module.mrbean.bytebuddy</shadedPattern>
41+
</relocation>
42+
</relocations>
43+
</configuration>
44+
</execution>
45+
</executions>
46+
</plugin>
47+
<plugin>
48+
<groupId>org.moditect</groupId>
49+
<artifactId>moditect-maven-plugin</artifactId>
50+
</plugin>
51+
</plugins>
52+
</build>
53+
<dependencies>
54+
<dependency>
55+
<groupId>com.fasterxml.jackson.core</groupId>
56+
<artifactId>jackson-core</artifactId>
57+
<version>3.0.0-SNAPSHOT</version>
58+
<scope>compile</scope>
59+
</dependency>
60+
<dependency>
61+
<groupId>com.fasterxml.jackson.core</groupId>
62+
<artifactId>jackson-databind</artifactId>
63+
<version>3.0.0-SNAPSHOT</version>
64+
<scope>compile</scope>
65+
</dependency>
66+
<dependency>
67+
<groupId>org.ow2.asm</groupId>
68+
<artifactId>asm</artifactId>
69+
<version>9.0</version>
70+
<scope>test</scope>
71+
</dependency>
72+
<dependency>
73+
<groupId>junit</groupId>
74+
<artifactId>junit</artifactId>
75+
<version>4.13.1</version>
76+
<scope>test</scope>
77+
<exclusions>
78+
<exclusion>
79+
<artifactId>hamcrest-core</artifactId>
80+
<groupId>org.hamcrest</groupId>
81+
</exclusion>
82+
</exclusions>
83+
</dependency>
84+
</dependencies>
85+
<properties>
86+
<osgi.private>net.bytebuddy.*</osgi.private>
87+
<packageVersion.dir>com/fasterxml/jackson/module/mrbean</packageVersion.dir>
88+
<packageVersion.package>${project.groupId}.mrbean</packageVersion.package>
89+
<osgi.export>${project.groupId}.mrbean.*;version=${project.version}</osgi.export>
90+
</properties>
91+
</project>

mrbean/src/main/java/com/fasterxml/jackson/module/mrbean/AbstractTypeMaterializer.java

+38-39
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.fasterxml.jackson.module.mrbean;
22

33
import java.lang.reflect.Modifier;
4-
import java.util.*;
54

65
import com.fasterxml.jackson.core.Version;
76
import com.fasterxml.jackson.core.Versioned;
@@ -94,16 +93,15 @@ protected static int collectDefaults() {
9493
protected String _defaultPackage = DEFAULT_PACKAGE_FOR_GENERATED;
9594

9695
/*
97-
/**********************************************************
96+
/**********************************************************************
9897
/* Construction, configuration
99-
/**********************************************************
98+
/**********************************************************************
10099
*/
101100

102101
public AbstractTypeMaterializer() {
103102
this(null);
104103
}
105104

106-
107105
/**
108106
* @param parentClassLoader Class loader to use for generated classes; if
109107
* null, will use class loader that loaded materializer itself.
@@ -168,11 +166,11 @@ public void setDefaultPackage(String defPkg)
168166
}
169167
_defaultPackage = defPkg;
170168
}
171-
169+
172170
/*
173-
/**********************************************************
171+
/**********************************************************************
174172
/* Public API
175-
/**********************************************************
173+
/**********************************************************************
176174
*/
177175

178176
/**
@@ -198,29 +196,6 @@ public JavaType resolveAbstractType(DeserializationConfig config, BeanDescriptio
198196
}
199197
return config.constructType(materializedType);
200198
}
201-
202-
/**
203-
* Older variant of {@link #resolveAbstractType(DeserializationConfig, BeanDescription)},
204-
* obsoleted in 2.7. Kept around in 2.7 for backwards compatibility.
205-
*<p>
206-
* TODO: remove from 2.9
207-
*/
208-
@Override
209-
@Deprecated
210-
public JavaType resolveAbstractType(DeserializationConfig config, JavaType type)
211-
{
212-
if (!_suitableType(type)) {
213-
return null;
214-
}
215-
Class<?> materializedType;
216-
if (type.hasGenericTypes()) {
217-
materializedType = materializeGenericType(config, type);
218-
} else {
219-
materializedType = materializeRawType(config,
220-
AnnotatedClassResolver.resolve(config, type, config));
221-
}
222-
return config.constructType(materializedType);
223-
}
224199

225200
/**
226201
* @since 2.4
@@ -267,8 +242,27 @@ protected Class<?> _materializeRawType(MapperConfig<?> config, AnnotatedClass ty
267242
protected Class<?> _loadAndResolve(String className, byte[] bytecode, Class<?> rawType) {
268243
return _classLoader.loadAndResolve(className, bytecode, rawType);
269244
}
270-
271-
// private until 2.9.9
245+
246+
/**
247+
* Overridable helper method called to check if given non-concrete type
248+
* should be materialized.
249+
*<p>
250+
* Default implementation will blocks all
251+
*<ul>
252+
* <li>primitive types</li>
253+
* <li>{@code Enums}</li>
254+
* <li>Container types (Collections, Maps; as per Jackson "container type")</li>
255+
* <li>Reference types (Jackson definition</li>
256+
*</ul>
257+
*<p>
258+
* Jackson 2.12 and earlier enumerated a small set of other types under
259+
* {@link java.lang} and {@link java.util}: 2.13 and later simply block
260+
* all types in {@code java.*}.
261+
*
262+
* @param type Type that we are asked to materialize
263+
*
264+
* @return True if materialization should proceed; {@code false} if not.
265+
*/
272266
protected boolean _suitableType(JavaType type)
273267
{
274268
// Future plans may include calling of this method for all kinds of abstract types.
@@ -278,16 +272,21 @@ protected boolean _suitableType(JavaType type)
278272
|| type.isEnumType() || type.isPrimitive()) {
279273
return false;
280274
}
281-
Class<?> cls = type.getRawClass();
275+
final Class<?> cls = type.getRawClass();
276+
277+
// In Jackson 2.12 we had:
278+
/*
282279
if ((cls == Number.class)
283280
// 22-Jun-2016, tatu: As per [#12], avoid these too
284281
|| (cls == Date.class) || (cls == Calendar.class)
285282
|| (cls == CharSequence.class) || (cls == Iterable.class) || (cls == Iterator.class)
286283
// 06-Feb-2019, tatu: [modules-base#74] and:
287284
|| (cls == java.io.Serializable.class)
288-
// 23-Apr-2021, tatu: [modules-base#132] minimal patch
289-
|| (cls == java.util.TimeZone.class)
290-
) {
285+
|| (cls == java.util.TimeZone.class)) {
286+
) {
287+
*/
288+
// 23-Apr-2021, tatu: Jackson 2.13, as per [modules-base#132], do this:
289+
if (cls.getName().startsWith("java.")) {
291290
return false;
292291
}
293292

@@ -303,9 +302,9 @@ protected boolean _suitableType(JavaType type)
303302
}
304303

305304
/*
306-
/**********************************************************
305+
/**********************************************************************
307306
/* Helper classes
308-
/**********************************************************
307+
/**********************************************************************
309308
*/
310309

311310
/**
@@ -331,7 +330,7 @@ public Class<?> loadAndResolve(String className, byte[] byteCode, Class<?> targe
331330
if (old != null && targetClass.isAssignableFrom(old)) {
332331
return old;
333332
}
334-
333+
335334
Class<?> impl;
336335
try {
337336
impl = defineClass(className, byteCode, 0, byteCode.length);

0 commit comments

Comments
 (0)