Skip to content

Commit

Permalink
Full fix of #132 for 2.13
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Apr 24, 2021
1 parent 4b92a98 commit 8664f15
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 39 deletions.
91 changes: 91 additions & 0 deletions mrbean/dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<artifactId>jackson-modules-base</artifactId>
<groupId>com.fasterxml.jackson.module</groupId>
<version>3.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>foobar-shaded</artifactId>
<packaging>bundle</packaging>
<name>Jackson module: Mr Bean</name>
<description>Functionality for implementing interfaces and abstract types
dynamically ("bean materialization"), integrated with Jackson (although usable externally as well)</description>
<url>https://github.com/FasterXML/jackson-modules-base</url>
<build>
<plugins>
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
</plugin>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>false</shadedArtifactAttached>
<shadedArtifactId>foobar-shaded</shadedArtifactId>
<artifactSet>
<includes>
<include>net.bytebuddy:byte-buddy</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>net.bytebuddy</pattern>
<shadedPattern>com.fasterxml.jackson.module.mrbean.bytebuddy</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.moditect</groupId>
<artifactId>moditect-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>3.0.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>3.0.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>9.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>hamcrest-core</artifactId>
<groupId>org.hamcrest</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<properties>
<osgi.private>net.bytebuddy.*</osgi.private>
<packageVersion.dir>com/fasterxml/jackson/module/mrbean</packageVersion.dir>
<packageVersion.package>${project.groupId}.mrbean</packageVersion.package>
<osgi.export>${project.groupId}.mrbean.*;version=${project.version}</osgi.export>
</properties>
</project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.fasterxml.jackson.module.mrbean;

import java.lang.reflect.Modifier;
import java.util.*;

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

/*
/**********************************************************
/**********************************************************************
/* Construction, configuration
/**********************************************************
/**********************************************************************
*/

public AbstractTypeMaterializer() {
this(null);
}


/**
* @param parentClassLoader Class loader to use for generated classes; if
* null, will use class loader that loaded materializer itself.
Expand Down Expand Up @@ -168,11 +166,11 @@ public void setDefaultPackage(String defPkg)
}
_defaultPackage = defPkg;
}

/*
/**********************************************************
/**********************************************************************
/* Public API
/**********************************************************
/**********************************************************************
*/

/**
Expand All @@ -198,29 +196,6 @@ public JavaType resolveAbstractType(DeserializationConfig config, BeanDescriptio
}
return config.constructType(materializedType);
}

/**
* Older variant of {@link #resolveAbstractType(DeserializationConfig, BeanDescription)},
* obsoleted in 2.7. Kept around in 2.7 for backwards compatibility.
*<p>
* TODO: remove from 2.9
*/
@Override
@Deprecated
public JavaType resolveAbstractType(DeserializationConfig config, JavaType type)
{
if (!_suitableType(type)) {
return null;
}
Class<?> materializedType;
if (type.hasGenericTypes()) {
materializedType = materializeGenericType(config, type);
} else {
materializedType = materializeRawType(config,
AnnotatedClassResolver.resolve(config, type, config));
}
return config.constructType(materializedType);
}

/**
* @since 2.4
Expand Down Expand Up @@ -267,8 +242,27 @@ protected Class<?> _materializeRawType(MapperConfig<?> config, AnnotatedClass ty
protected Class<?> _loadAndResolve(String className, byte[] bytecode, Class<?> rawType) {
return _classLoader.loadAndResolve(className, bytecode, rawType);
}

// private until 2.9.9

/**
* Overridable helper method called to check if given non-concrete type
* should be materialized.
*<p>
* Default implementation will blocks all
*<ul>
* <li>primitive types</li>
* <li>{@code Enums}</li>
* <li>Container types (Collections, Maps; as per Jackson "container type")</li>
* <li>Reference types (Jackson definition</li>
*</ul>
*<p>
* Jackson 2.12 and earlier enumerated a small set of other types under
* {@link java.lang} and {@link java.util}: 2.13 and later simply block
* all types in {@code java.*}.
*
* @param type Type that we are asked to materialize
*
* @return True if materialization should proceed; {@code false} if not.
*/
protected boolean _suitableType(JavaType type)
{
// Future plans may include calling of this method for all kinds of abstract types.
Expand All @@ -278,16 +272,21 @@ protected boolean _suitableType(JavaType type)
|| type.isEnumType() || type.isPrimitive()) {
return false;
}
Class<?> cls = type.getRawClass();
final Class<?> cls = type.getRawClass();

// In Jackson 2.12 we had:
/*
if ((cls == Number.class)
// 22-Jun-2016, tatu: As per [#12], avoid these too
|| (cls == Date.class) || (cls == Calendar.class)
|| (cls == CharSequence.class) || (cls == Iterable.class) || (cls == Iterator.class)
// 06-Feb-2019, tatu: [modules-base#74] and:
|| (cls == java.io.Serializable.class)
// 23-Apr-2021, tatu: [modules-base#132] minimal patch
|| (cls == java.util.TimeZone.class)
) {
|| (cls == java.util.TimeZone.class)) {
) {
*/
// 23-Apr-2021, tatu: Jackson 2.13, as per [modules-base#132], do this:
if (cls.getName().startsWith("java.")) {
return false;
}

Expand All @@ -303,9 +302,9 @@ protected boolean _suitableType(JavaType type)
}

/*
/**********************************************************
/**********************************************************************
/* Helper classes
/**********************************************************
/**********************************************************************
*/

/**
Expand All @@ -331,7 +330,7 @@ public Class<?> loadAndResolve(String className, byte[] byteCode, Class<?> targe
if (old != null && targetClass.isAssignableFrom(old)) {
return old;
}

Class<?> impl;
try {
impl = defineClass(className, byteCode, 0, byteCode.length);
Expand Down

0 comments on commit 8664f15

Please sign in to comment.