com.fasterxml.jackson.module.blackbird.deser.CreatorOptimizer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jackson-module-blackbird Show documentation
Show all versions of jackson-module-blackbird Show documentation
Jackson (https://github.com/FasterXML/jackson) extension module
that uses LambdaMetafactory based code generation to replace reflection calls.
The newest version!
package com.fasterxml.jackson.module.blackbird.deser;
import java.lang.invoke.LambdaMetafactory;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Stream;
import com.fasterxml.jackson.databind.deser.ValueInstantiator;
import com.fasterxml.jackson.databind.deser.std.StdValueInstantiator;
import com.fasterxml.jackson.databind.introspect.AnnotatedWithParams;
import com.fasterxml.jackson.module.blackbird.util.Unchecked;
import static java.lang.invoke.MethodHandles.lookup;
import static java.lang.invoke.MethodType.methodType;
/**
* Helper class that tries to generate {@link ValueInstantiator} class
* that calls constructors and/or factory methods directly, instead
* of using Reflection.
*/
public class CreatorOptimizer
{
protected final Class> _valueClass;
protected final StdValueInstantiator _originalInstantiator;
private final MethodHandles.Lookup _lookup;
public CreatorOptimizer(Class> valueClass, MethodHandles.Lookup lookup, StdValueInstantiator orig)
{
_valueClass = valueClass;
_originalInstantiator = orig;
_lookup = lookup;
}
public ValueInstantiator createOptimized()
{
/* [Issue#11]: Need to avoid optimizing if we use delegate-based creators. */
if (_originalInstantiator.canCreateUsingDelegate()) {
return null;
}
if (_lookup == null) {
return null;
}
AnnotatedWithParams argsCreator = _originalInstantiator.getWithArgsCreator();
Function
© 2015 - 2025 Weber Informatics LLC | Privacy Policy