Top Description Inners Fields Constructors Methods
com.fasterxml.jackson.module.mrbean

public Class AbstractTypeMaterializer

extends AbstractTypeResolver
implements Versioned
Class Inheritance
All Implemented Interfaces
com.fasterxml.jackson.core.Versioned
Imports
java.lang.reflect.Modifier, com.fasterxml.jackson.core.Version, .Versioned, com.fasterxml.jackson.databind.AbstractTypeResolver, .BeanDescription, .DeserializationConfig, .JavaType, com.fasterxml.jackson.databind.cfg.MapperConfig, com.fasterxml.jackson.databind.introspect.AnnotatedClass, .AnnotatedClassResolver

Nifty class for pulling implementations of classes out of thin air.

... friends call him Mister Bean... :-)

Authors
tatu, sunny

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
AbstractTypeMaterializer.Feature

Enumeration that defines togglable features that guide the serialization feature.

pack-priv static class
AbstractTypeMaterializer.MyClassLoader

To support actual dynamic loading of bytecode we need a simple custom classloader.

Field Summary

Modifier and TypeField and Description
protected final AbstractTypeMaterializer.MyClassLoader
_classLoader

We will use per-materializer class loader for now; would be nice to find a way to reduce number of class loaders (and hence number of generated classes!) constructed...

protected String
_defaultPackage

Package name to use as prefix for generated classes.

protected int
_featureFlags

Bit set that contains all enabled features

protected static final int
DEFAULT_FEATURE_FLAGS

Bitfield (set of flags) of all Features that are enabled by default.

public static final String
DEFAULT_PACKAGE_FOR_GENERATED

Default package to use for generated classes.

Constructor Summary

AccessConstructor and Description
public
public
AbstractTypeMaterializer(ClassLoader
Class loader to use for generated classes; if null, will use class loader that loaded materializer itself.
parentClassLoader
)

Method Summary

Modifier and TypeMethod and Description
protected Class<?>
_loadAndResolve(String className, byte[] bytecode, Class<?> rawType)

protected Class<?>
_materializeRawType(MapperConfig<?> config, AnnotatedClass typeDef, String nameToUse)

protected boolean

Returns:

True if materialization should proceed; false if not.
_suitableType
(JavaType
Type that we are asked to materialize
type
)

Overridable helper method called to check if given non-concrete type should be materialized.

public void
disable(AbstractTypeMaterializer.Feature f)

Method for disabling specified feature.

public void
enable(AbstractTypeMaterializer.Feature f)

Method for enabling specified feature.

public final boolean
isEnabled(AbstractTypeMaterializer.Feature f)

Method for checking whether given feature is enabled or not

public Class<?>
public Class<?>
materializeRawType(MapperConfig<?> config, AnnotatedClass typeDef)

Note

should not be called for generic types.

public JavaType
resolveAbstractType(DeserializationConfig
Configuration in use
config
,
BeanDescription
Description of the POJO type to resolve
beanDesc
)

Overrides com.fasterxml.jackson.databind.AbstractTypeResolver.resolveAbstractType.

Entry-point for AbstractTypeResolver that Jackson calls to materialize an abstract type.

public void
set(AbstractTypeMaterializer.Feature f, boolean state)

Method for enabling or disabling specified feature.

public void
setDefaultPackage(String defPkg)

Method for specifying package to use for generated classes.

public Version
version()

Implements com.fasterxml.jackson.core.Versioned.version.

Method that will return version information stored in and read from jar that contains this class.

Inherited from com.fasterxml.jackson.databind.AbstractTypeResolver:
findTypeMappingresolveAbstractType

Field Detail

_classLoaderback to summary
protected final AbstractTypeMaterializer.MyClassLoader _classLoader

We will use per-materializer class loader for now; would be nice to find a way to reduce number of class loaders (and hence number of generated classes!) constructed...

_defaultPackageback to summary
protected String _defaultPackage

Package name to use as prefix for generated classes.

_featureFlagsback to summary
protected int _featureFlags

Bit set that contains all enabled features

DEFAULT_FEATURE_FLAGSback to summary
protected static final int DEFAULT_FEATURE_FLAGS

Bitfield (set of flags) of all Features that are enabled by default.

DEFAULT_PACKAGE_FOR_GENERATEDback to summary
public static final String DEFAULT_PACKAGE_FOR_GENERATED

Default package to use for generated classes.

Constructor Detail

AbstractTypeMaterializerback to summary
public AbstractTypeMaterializer()
AbstractTypeMaterializerback to summary
public AbstractTypeMaterializer(ClassLoader parentClassLoader)
Parameters
parentClassLoader:ClassLoader

Class loader to use for generated classes; if null, will use class loader that loaded materializer itself.

Method Detail

_loadAndResolveback to summary
protected Class<?> _loadAndResolve(String className, byte[] bytecode, Class<?> rawType)
_materializeRawTypeback to summary
protected Class<?> _materializeRawType(MapperConfig<?> config, AnnotatedClass typeDef, String nameToUse)
_suitableTypeback to summary
protected boolean _suitableType(JavaType type)

Overridable helper method called to check if given non-concrete type should be materialized.

Default implementation will blocks all

  • primitive types
  • Enums
  • Container types (Collections, Maps; as per Jackson "container type")
  • Reference types (Jackson definition

Jackson 2.12 and earlier enumerated a small set of other types under java.lang and java.util: 2.13 and later simply block all types in java.*.

Parameters
type:JavaType

Type that we are asked to materialize

Returns:boolean

True if materialization should proceed; false if not.

disableback to summary
public void disable(AbstractTypeMaterializer.Feature f)

Method for disabling specified feature.

enableback to summary
public void enable(AbstractTypeMaterializer.Feature f)

Method for enabling specified feature.

isEnabledback to summary
public final boolean isEnabled(AbstractTypeMaterializer.Feature f)

Method for checking whether given feature is enabled or not

materializeGenericTypeback to summary
public Class<?> materializeGenericType(MapperConfig<?> config, JavaType type)
Since
2.4
materializeRawTypeback to summary
public Class<?> materializeRawType(MapperConfig<?> config, AnnotatedClass typeDef)

Note

should not be called for generic types.

Since
2.4
resolveAbstractTypeback to summary
public JavaType resolveAbstractType(DeserializationConfig config, BeanDescription beanDesc)

Overrides com.fasterxml.jackson.databind.AbstractTypeResolver.resolveAbstractType.

Entry-point for AbstractTypeResolver that Jackson calls to materialize an abstract type.

Parameters
config:DeserializationConfig

Doc from com.fasterxml.jackson.databind.AbstractTypeResolver.resolveAbstractType.

Configuration in use

beanDesc:BeanDescription

Doc from com.fasterxml.jackson.databind.AbstractTypeResolver.resolveAbstractType.

Description of the POJO type to resolve

Returns:JavaType

Doc from com.fasterxml.jackson.databind.AbstractTypeResolver.resolveAbstractType.

Resolved concrete type (which should retain generic type parameters of input type, if any), if resolution succeeds; null if resolver does not know how to resolve given type

Annotations
@Override
setback to summary
public void set(AbstractTypeMaterializer.Feature f, boolean state)

Method for enabling or disabling specified feature.

setDefaultPackageback to summary
public void setDefaultPackage(String defPkg)

Method for specifying package to use for generated classes.

versionback to summary
public Version version()

Implements com.fasterxml.jackson.core.Versioned.version.

Method that will return version information stored in and read from jar that contains this class.

Returns:Version

Doc from com.fasterxml.jackson.core.Versioned.version.

Version of the component

Annotations
@Override
com.fasterxml.jackson.module.mrbean back to summary

public final Enum AbstractTypeMaterializer.Feature

extends Enum<AbstractTypeMaterializer.Feature>
Class Inheritance

Enumeration that defines togglable features that guide the serialization feature.

Field Summary

Modifier and TypeField and Description
pack-priv final boolean
public static final AbstractTypeMaterializer.Feature
FAIL_ON_NON_PUBLIC_TYPES

Feature that determines what happens when attempt is made to generate implementation of non-public class or interface.

public static final AbstractTypeMaterializer.Feature
FAIL_ON_UNMATERIALIZED_METHOD

Feature that determines what happens if an "unrecognized" (non-getter, non-setter) abstract method is encountered: if set to true, will throw an exception during materialization; if false, will materialize method that throws exception only if called.

Constructor Summary

AccessConstructor and Description
private
Feature(boolean defaultState)

Method Summary

Modifier and TypeMethod and Description
protected static int
public boolean
public int
public static AbstractTypeMaterializer.Feature
public static AbstractTypeMaterializer.Feature[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

_defaultStateback to summary
pack-priv final boolean _defaultState
FAIL_ON_NON_PUBLIC_TYPESback to summary
public static final AbstractTypeMaterializer.Feature FAIL_ON_NON_PUBLIC_TYPES

Feature that determines what happens when attempt is made to generate implementation of non-public class or interface. If true, an exception is thrown; if false, will just quietly ignore attempts.

FAIL_ON_UNMATERIALIZED_METHODback to summary
public static final AbstractTypeMaterializer.Feature FAIL_ON_UNMATERIALIZED_METHOD

Feature that determines what happens if an "unrecognized" (non-getter, non-setter) abstract method is encountered: if set to true, will throw an exception during materialization; if false, will materialize method that throws exception only if called.

Constructor Detail

Featureback to summary
private Feature(boolean defaultState)

Method Detail

collectDefaultsback to summary
protected static int collectDefaults()
enabledByDefaultback to summary
public boolean enabledByDefault()
getMaskback to summary
public int getMask()
valueOfback to summary
public static AbstractTypeMaterializer.Feature valueOf(String name)
valuesback to summary
public static AbstractTypeMaterializer.Feature[] values()
com.fasterxml.jackson.module.mrbean back to summary

pack-priv Class AbstractTypeMaterializer.MyClassLoader

extends ClassLoader
Class Inheritance

To support actual dynamic loading of bytecode we need a simple custom classloader.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public Class<?>
loadAndResolve(String className, byte[] byteCode, Class<?>
Interface or abstract class that class to load should extend or implement
targetClass
)

Inherited from java.lang.ClassLoader:
clearAssertionStatusdefineClassdefineClassdefineClassdefineClassdefinePackagefindClassfindClassfindLibraryfindLoadedClassfindResourcefindResourcefindResourcesfindSystemClassgetClassLoadingLockgetDefinedPackagegetDefinedPackagesgetNamegetPackagegetPackagesgetParentgetPlatformClassLoadergetResourcegetResourceAsStreamgetResourcesgetSystemClassLoadergetSystemResourcegetSystemResourceAsStreamgetSystemResourcesgetUnnamedModuleisRegisteredAsParallelCapableloadClassloadClassregisterAsParallelCapableresolveClassresourcessetClassAssertionStatussetDefaultAssertionStatussetPackageAssertionStatussetSigners

Constructor Detail

MyClassLoaderback to summary
public MyClassLoader(ClassLoader parent)

Method Detail

loadAndResolveback to summary
public Class<?> loadAndResolve(String className, byte[] byteCode, Class<?> targetClass) throws IllegalArgumentException
Parameters
targetClass:Class<?>

Interface or abstract class that class to load should extend or implement