com.fasterxml.jackson.databind.deser.std.EnumDeserializer.java Source code

Java tutorial

Introduction

Here is the source code for com.fasterxml.jackson.databind.deser.std.EnumDeserializer.java

Source

package com.fasterxml.jackson.databind.deser.std;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.DeserializationConfig;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.introspect.AnnotatedMethod;
import com.fasterxml.jackson.databind.util.ClassUtil;
import com.fasterxml.jackson.databind.util.EnumResolver;
import java.lang.reflect.Method;

public class EnumDeserializer extends StdScalarDeserializer<Enum<?>> {
    protected final EnumResolver<?> _resolver;

    public EnumDeserializer(EnumResolver<?> paramEnumResolver) {
        super(Enum.class);
        this._resolver = paramEnumResolver;
    }

    public static JsonDeserializer<?> deserializerForCreator(DeserializationConfig paramDeserializationConfig,
            Class<?> paramClass, AnnotatedMethod paramAnnotatedMethod) {
        Class localClass = paramAnnotatedMethod.getRawParameterType(0);
        Object localObject;
        if (localClass == String.class)
            localObject = null;
        while (true) {
            if (paramDeserializationConfig.canOverrideAccessModifiers())
                ClassUtil.checkAndFixAccess(paramAnnotatedMethod.getMember());
            return new FactoryBasedDeserializer(paramClass, paramAnnotatedMethod, (Class) localObject);
            if ((localClass == Integer.TYPE) || (localClass == Integer.class)) {
                localObject = Integer.class;
            } else {
                if ((localClass != Long.TYPE) && (localClass != Long.class))
                    break;
                localObject = Long.class;
            }
        }
        throw new IllegalArgumentException("Parameter #0 type for factory method (" + paramAnnotatedMethod
                + ") not suitable, must be java.lang.String or int/Integer/long/Long");
    }

    public Enum<?> deserialize(JsonParser paramJsonParser, DeserializationContext paramDeserializationContext) {
        JsonToken localJsonToken = paramJsonParser.getCurrentToken();
        Enum localEnum;
        if ((localJsonToken == JsonToken.VALUE_STRING) || (localJsonToken == JsonToken.FIELD_NAME)) {
            String str = paramJsonParser.getText();
            localEnum = this._resolver.findEnum(str);
            if ((localEnum == null) && (!paramDeserializationContext
                    .isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)))
                throw paramDeserializationContext.weirdStringException(str, this._resolver.getEnumClass(),
                        "value not one of declared Enum instance names");
        } else if (localJsonToken == JsonToken.VALUE_NUMBER_INT) {
            if (paramDeserializationContext.isEnabled(DeserializationFeature.FAIL_ON_NUMBERS_FOR_ENUMS))
                throw paramDeserializationContext.mappingException(
                        "Not allowed to deserialize Enum value out of JSON number (disable DeserializationConfig.DeserializationFeature.FAIL_ON_NUMBERS_FOR_ENUMS to allow)");
            int i = paramJsonParser.getIntValue();
            localEnum = this._resolver.getEnum(i);
            if ((localEnum == null) && (!paramDeserializationContext
                    .isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)))
                throw paramDeserializationContext.weirdNumberException(Integer.valueOf(i),
                        this._resolver.getEnumClass(),
                        "index value outside legal index range [0.." + this._resolver.lastValidIndex() + "]");
        } else {
            throw paramDeserializationContext.mappingException(this._resolver.getEnumClass());
        }
        return localEnum;
    }

    public boolean isCachable() {
        return true;
    }

    protected static class FactoryBasedDeserializer extends StdScalarDeserializer<Object> {
        protected final Class<?> _enumClass;
        protected final Method _factory;
        protected final Class<?> _inputType;

        public FactoryBasedDeserializer(Class<?> paramClass1, AnnotatedMethod paramAnnotatedMethod,
                Class<?> paramClass2) {
            super();
            this._enumClass = paramClass1;
            this._factory = paramAnnotatedMethod.getAnnotated();
            this._inputType = paramClass2;
        }

        public Object deserialize(JsonParser paramJsonParser, DeserializationContext paramDeserializationContext) {
            Object localObject1;
            if (this._inputType == null)
                localObject1 = paramJsonParser.getText();
            try {
                while (true) {
                    Object localObject2 = this._factory.invoke(this._enumClass, new Object[] { localObject1 });
                    return localObject2;
                    if (this._inputType == Integer.class) {
                        localObject1 = Integer.valueOf(paramJsonParser.getValueAsInt());
                    } else {
                        if (this._inputType != Long.class)
                            break;
                        localObject1 = Long.valueOf(paramJsonParser.getValueAsLong());
                    }
                }
                throw paramDeserializationContext.mappingException(this._enumClass);
            } catch (Exception localException) {
                ClassUtil.unwrapAndThrowAsIAE(localException);
            }
            return null;
        }
    }
}

/* Location:           /Users/dantheman/src/fffffffffattttt/basis/classes_dex2jar.jar
 * Qualified Name:     com.fasterxml.jackson.databind.deser.std.EnumDeserializer
 * JD-Core Version:    0.6.2
 */