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

Java tutorial

Introduction

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

Source

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

import com.fasterxml.jackson.core.io.NumberInput;
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.KeyDeserializer;
import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
import com.fasterxml.jackson.databind.introspect.AnnotatedMethod;
import com.fasterxml.jackson.databind.util.ClassUtil;
import com.fasterxml.jackson.databind.util.EnumResolver;
import java.io.IOException;
import java.io.Serializable;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.UUID;

public abstract class StdKeyDeserializer extends KeyDeserializer implements Serializable {
    protected final Class<?> _keyClass;

    protected StdKeyDeserializer(Class<?> paramClass) {
        this._keyClass = paramClass;
    }

    protected abstract Object _parse(String paramString, DeserializationContext paramDeserializationContext);

    protected double _parseDouble(String paramString) {
        return NumberInput.parseDouble(paramString);
    }

    protected int _parseInt(String paramString) {
        return Integer.parseInt(paramString);
    }

    protected long _parseLong(String paramString) {
        return Long.parseLong(paramString);
    }

    public final Object deserializeKey(String paramString, DeserializationContext paramDeserializationContext) {
        if (paramString == null)
            ;
        do {
            return null;
            try {
                Object localObject = _parse(paramString, paramDeserializationContext);
                if (localObject != null)
                    return localObject;
            } catch (Exception localException) {
                throw paramDeserializationContext.weirdKeyException(this._keyClass, paramString,
                        "not a valid representation: " + localException.getMessage());
            }
        } while ((this._keyClass.isEnum()) && (paramDeserializationContext.getConfig()
                .isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)));
        throw paramDeserializationContext.weirdKeyException(this._keyClass, paramString,
                "not a valid representation");
    }

    public Class<?> getKeyClass() {
        return this._keyClass;
    }

    @JacksonStdImpl
    static final class BoolKD extends StdKeyDeserializer {
        BoolKD() {
            super();
        }

        public Boolean _parse(String paramString, DeserializationContext paramDeserializationContext) {
            if ("true".equals(paramString))
                return Boolean.TRUE;
            if ("false".equals(paramString))
                return Boolean.FALSE;
            throw paramDeserializationContext.weirdKeyException(this._keyClass, paramString,
                    "value not 'true' or 'false'");
        }
    }

    @JacksonStdImpl
    static final class ByteKD extends StdKeyDeserializer {
        ByteKD() {
            super();
        }

        public Byte _parse(String paramString, DeserializationContext paramDeserializationContext) {
            int i = _parseInt(paramString);
            if ((i < -128) || (i > 255))
                throw paramDeserializationContext.weirdKeyException(this._keyClass, paramString,
                        "overflow, value can not be represented as 8-bit value");
            return Byte.valueOf((byte) i);
        }
    }

    @JacksonStdImpl
    static final class CalendarKD extends StdKeyDeserializer {
        protected CalendarKD() {
            super();
        }

        public Object _parse(String paramString, DeserializationContext paramDeserializationContext) {
            Date localDate = paramDeserializationContext.parseDate(paramString);
            if (localDate == null)
                return null;
            return paramDeserializationContext.constructCalendar(localDate);
        }
    }

    @JacksonStdImpl
    static final class CharKD extends StdKeyDeserializer {
        CharKD() {
            super();
        }

        public Character _parse(String paramString, DeserializationContext paramDeserializationContext) {
            if (paramString.length() == 1)
                return Character.valueOf(paramString.charAt(0));
            throw paramDeserializationContext.weirdKeyException(this._keyClass, paramString,
                    "can only convert 1-character Strings");
        }
    }

    @JacksonStdImpl
    static final class DateKD extends StdKeyDeserializer {
        protected DateKD() {
            super();
        }

        public Object _parse(String paramString, DeserializationContext paramDeserializationContext) {
            return paramDeserializationContext.parseDate(paramString);
        }
    }

    static final class DelegatingKD extends KeyDeserializer implements Serializable {
        protected final JsonDeserializer<?> _delegate;
        protected final Class<?> _keyClass;

        protected DelegatingKD(Class<?> paramClass, JsonDeserializer<?> paramJsonDeserializer) {
            this._keyClass = paramClass;
            this._delegate = paramJsonDeserializer;
        }

        public final Object deserializeKey(String paramString, DeserializationContext paramDeserializationContext) {
            Object localObject2;
            if (paramString == null)
                localObject2 = null;
            while (true) {
                return localObject2;
                try {
                    Object localObject1 = this._delegate.deserialize(paramDeserializationContext.getParser(),
                            paramDeserializationContext);
                    localObject2 = localObject1;
                    if (localObject2 != null)
                        continue;
                    throw paramDeserializationContext.weirdKeyException(this._keyClass, paramString,
                            "not a valid representation");
                } catch (Exception localException) {
                    throw paramDeserializationContext.weirdKeyException(this._keyClass, paramString,
                            "not a valid representation: " + localException.getMessage());
                }
            }
        }
    }

    @JacksonStdImpl
    static final class DoubleKD extends StdKeyDeserializer {
        DoubleKD() {
            super();
        }

        public Double _parse(String paramString, DeserializationContext paramDeserializationContext) {
            return Double.valueOf(_parseDouble(paramString));
        }
    }

    @JacksonStdImpl
    static final class EnumKD extends StdKeyDeserializer {
        protected final AnnotatedMethod _factory;
        protected final EnumResolver<?> _resolver;

        protected EnumKD(EnumResolver<?> paramEnumResolver, AnnotatedMethod paramAnnotatedMethod) {
            super();
            this._resolver = paramEnumResolver;
            this._factory = paramAnnotatedMethod;
        }

        public Object _parse(String paramString, DeserializationContext paramDeserializationContext) {
            if (this._factory != null)
                ;
            Object localObject1;
            do {
                try {
                    Object localObject2 = this._factory.call1(paramString);
                    localObject1 = localObject2;
                    return localObject1;
                } catch (Exception localException) {
                    ClassUtil.unwrapAndThrowAsIAE(localException);
                }
                localObject1 = this._resolver.findEnum(paramString);
            } while ((localObject1 != null) || (paramDeserializationContext.getConfig()
                    .isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)));
            throw paramDeserializationContext.weirdKeyException(this._keyClass, paramString,
                    "not one of values for Enum class");
        }
    }

    @JacksonStdImpl
    static final class FloatKD extends StdKeyDeserializer {
        FloatKD() {
            super();
        }

        public Float _parse(String paramString, DeserializationContext paramDeserializationContext) {
            return Float.valueOf((float) _parseDouble(paramString));
        }
    }

    @JacksonStdImpl
    static final class IntKD extends StdKeyDeserializer {
        IntKD() {
            super();
        }

        public Integer _parse(String paramString, DeserializationContext paramDeserializationContext) {
            return Integer.valueOf(_parseInt(paramString));
        }
    }

    @JacksonStdImpl
    static final class LocaleKD extends StdKeyDeserializer {
        protected JdkDeserializers.LocaleDeserializer _localeDeserializer = new JdkDeserializers.LocaleDeserializer();

        LocaleKD() {
            super();
        }

        protected Locale _parse(String paramString, DeserializationContext paramDeserializationContext) {
            try {
                Locale localLocale = this._localeDeserializer._deserialize(paramString,
                        paramDeserializationContext);
                return localLocale;
            } catch (IOException localIOException) {
            }
            throw paramDeserializationContext.weirdKeyException(this._keyClass, paramString,
                    "unable to parse key as locale");
        }
    }

    @JacksonStdImpl
    static final class LongKD extends StdKeyDeserializer {
        LongKD() {
            super();
        }

        public Long _parse(String paramString, DeserializationContext paramDeserializationContext) {
            return Long.valueOf(_parseLong(paramString));
        }
    }

    @JacksonStdImpl
    static final class ShortKD extends StdKeyDeserializer {
        ShortKD() {
            super();
        }

        public Short _parse(String paramString, DeserializationContext paramDeserializationContext) {
            int i = _parseInt(paramString);
            if ((i < -32768) || (i > 32767))
                throw paramDeserializationContext.weirdKeyException(this._keyClass, paramString,
                        "overflow, value can not be represented as 16-bit value");
            return Short.valueOf((short) i);
        }
    }

    static final class StringCtorKeyDeserializer extends StdKeyDeserializer {
        protected final Constructor<?> _ctor;

        public StringCtorKeyDeserializer(Constructor<?> paramConstructor) {
            super();
            this._ctor = paramConstructor;
        }

        public Object _parse(String paramString, DeserializationContext paramDeserializationContext) {
            return this._ctor.newInstance(new Object[] { paramString });
        }
    }

    static final class StringFactoryKeyDeserializer extends StdKeyDeserializer {
        final Method _factoryMethod;

        public StringFactoryKeyDeserializer(Method paramMethod) {
            super();
            this._factoryMethod = paramMethod;
        }

        public Object _parse(String paramString, DeserializationContext paramDeserializationContext) {
            return this._factoryMethod.invoke(null, new Object[] { paramString });
        }
    }

    @JacksonStdImpl
    static final class StringKD extends StdKeyDeserializer {
        private static final StringKD sObject = new StringKD(Object.class);
        private static final StringKD sString = new StringKD(String.class);

        private StringKD(Class<?> paramClass) {
            super();
        }

        public static StringKD forType(Class<?> paramClass) {
            if (paramClass == String.class)
                return sString;
            if (paramClass == Object.class)
                return sObject;
            return new StringKD(paramClass);
        }

        public String _parse(String paramString, DeserializationContext paramDeserializationContext) {
            return paramString;
        }
    }

    @JacksonStdImpl
    static final class UuidKD extends StdKeyDeserializer {
        protected UuidKD() {
            super();
        }

        public Object _parse(String paramString, DeserializationContext paramDeserializationContext) {
            return UUID.fromString(paramString);
        }
    }
}

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