package com.fasterxml.jackson.databind.deser.std;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.deser.KeyDeserializers;
import com.fasterxml.jackson.databind.introspect.AnnotatedMethod;
import com.fasterxml.jackson.databind.util.ClassUtil;
import com.fasterxml.jackson.databind.util.EnumResolver;
public class StdKeyDeserializers
implements KeyDeserializers, java.io.Serializable
{
private static final long serialVersionUID = 1L;
public static KeyDeserializer constructEnumKeyDeserializer(EnumResolver enumResolver) {
return new StdKeyDeserializer.EnumKD(enumResolver, null);
}
public static KeyDeserializer constructEnumKeyDeserializer(EnumResolver enumResolver,
AnnotatedMethod factory) {
return new StdKeyDeserializer.EnumKD(enumResolver, factory);
}
public static KeyDeserializer constructDelegatingKeyDeserializer(DeserializationConfig config,
JavaType type, JsonDeserializer<?> deser)
{
return new StdKeyDeserializer.DelegatingKD(type.getRawClass(), deser);
}
public static KeyDeserializer findStringBasedKeyDeserializer(DeserializationConfig config,
JavaType type)
{
BeanDescription beanDesc = config.introspect(type);
Constructor<?> ctor = beanDesc.findSingleArgConstructor(String.class);
if (ctor != null) {
if (config.canOverrideAccessModifiers()) {
ClassUtil.checkAndFixAccess(ctor, config.isEnabled(MapperFeature.OVERRIDE_PUBLIC_ACCESS_MODIFIERS));
}
return new StdKeyDeserializer.StringCtorKeyDeserializer(ctor);
}
Method m = beanDesc.findFactoryMethod(String.class);
if (m != null){
if (config.canOverrideAccessModifiers()) {
ClassUtil.checkAndFixAccess(m, config.isEnabled(MapperFeature.OVERRIDE_PUBLIC_ACCESS_MODIFIERS));
}
return new StdKeyDeserializer.StringFactoryKeyDeserializer(m);
}
return null;
}
@Override
public KeyDeserializer findKeyDeserializer(JavaType type,
DeserializationConfig config, BeanDescription beanDesc) throws JsonMappingException
{
Class<?> raw = type.getRawClass();
if (raw.isPrimitive()) {
raw = ClassUtil.wrapperType(raw);
}
return StdKeyDeserializer.forType(raw);
}
}