导航菜单

页面标题

页面副标题

Kreate v1.5.0 - JsonPlugin.java 源代码

正在查看: Kreate v1.5.0 应用的 JsonPlugin.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package io.ktor.client.plugins.json;

import io.ktor.client.HttpClient;
import io.ktor.client.plugins.HttpClientPlugin;
import io.ktor.client.request.HttpRequestPipeline;
import io.ktor.client.statement.HttpResponsePipeline;
import io.ktor.http.ContentType;
import io.ktor.http.ContentTypeMatcher;
import io.ktor.http.LinkHeader;
import io.ktor.util.AttributeKey;
import io.ktor.util.reflect.TypeInfo;
import io.ktor.utils.io.KtorDsl;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import kotlin.Deprecated;
import kotlin.DeprecationLevel;
import kotlin.Metadata;
import kotlin.Unit;
import kotlin.collections.CollectionsKt;
import kotlin.collections.SetsKt;
import kotlin.jvm.functions.Function1;
import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlin.jvm.internal.Intrinsics;
import kotlin.jvm.internal.Reflection;
import kotlin.reflect.KClass;
import kotlin.reflect.KType;

@Deprecated(level = DeprecationLevel.ERROR, message = "Please use ContentNegotiation plugin: https://ktor.io/docs/migration-to-20x.html#serialization-client")
@Metadata(d1 = {"\u0000:\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010 \n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\"\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0010\u000b\n\u0002\b\r\b\u0007\u0018\u0000 \u001d2\u00020\u0001:\u0002\u001e\u001dBE\b\u0000\u0012\u0006\u0010\u0003\u001a\u00020\u0002\u0012\u000e\b\u0002\u0010\u0006\u001a\b\u0012\u0004\u0012\u00020\u00050\u0004\u0012\u000e\b\u0002\u0010\b\u001a\b\u0012\u0004\u0012\u00020\u00070\u0004\u0012\u0012\b\u0002\u0010\u000b\u001a\f\u0012\b\u0012\u0006\u0012\u0002\b\u00030\n0\t¢\u0006\u0004\b\f\u0010\rB\u0011\b\u0010\u0012\u0006\u0010\u000f\u001a\u00020\u000e¢\u0006\u0004\b\f\u0010\u0010J\u0017\u0010\u0015\u001a\u00020\u00122\u0006\u0010\u0011\u001a\u00020\u0005H\u0000¢\u0006\u0004\b\u0013\u0010\u0014R\u0017\u0010\u0003\u001a\u00020\u00028\u0006¢\u0006\f\n\u0004\b\u0003\u0010\u0016\u001a\u0004\b\u0017\u0010\u0018R\u001d\u0010\u0006\u001a\b\u0012\u0004\u0012\u00020\u00050\u00048\u0006¢\u0006\f\n\u0004\b\u0006\u0010\u0019\u001a\u0004\b\u001a\u0010\u001bR\u001a\u0010\b\u001a\b\u0012\u0004\u0012\u00020\u00070\u00048\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\b\u0010\u0019R\u001e\u0010\u000b\u001a\f\u0012\b\u0012\u0006\u0012\u0002\b\u00030\n0\t8\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\u000b\u0010\u001c¨\u0006\u001f"}, d2 = {"Lio/ktor/client/plugins/json/JsonPlugin;", "", "Lio/ktor/client/plugins/json/JsonSerializer;", "serializer", "", "Lio/ktor/http/ContentType;", "acceptContentTypes", "Lio/ktor/http/ContentTypeMatcher;", "receiveContentTypeMatchers", "", "Lkotlin/reflect/KClass;", "ignoredTypes", "<init>", "(Lio/ktor/client/plugins/json/JsonSerializer;Ljava/util/List;Ljava/util/List;Ljava/util/Set;)V", "Lio/ktor/client/plugins/json/JsonPlugin$Config;", "config", "(Lio/ktor/client/plugins/json/JsonPlugin$Config;)V", "contentType", "", "canHandle$ktor_client_json", "(Lio/ktor/http/ContentType;)Z", "canHandle", "Lio/ktor/client/plugins/json/JsonSerializer;", "getSerializer", "()Lio/ktor/client/plugins/json/JsonSerializer;", "Ljava/util/List;", "getAcceptContentTypes", "()Ljava/util/List;", "Ljava/util/Set;", "Plugin", "Config", "ktor-client-json"}, k = 1, mv = {2, 1, 0}, xi = 48)
public final class JsonPlugin {

    public static final Companion INSTANCE = new Companion(0 == true ? 1 : 0);
    private static final AttributeKey<JsonPlugin> key;
    private final List<ContentType> acceptContentTypes;
    private final Set<KClass<?>> ignoredTypes;
    private final List<ContentTypeMatcher> receiveContentTypeMatchers;
    private final JsonSerializer serializer;

    public JsonPlugin(JsonSerializer serializer, List<ContentType> acceptContentTypes, List<? extends ContentTypeMatcher> receiveContentTypeMatchers, Set<? extends KClass<?>> ignoredTypes) {
        Intrinsics.checkNotNullParameter(serializer, "serializer");
        Intrinsics.checkNotNullParameter(acceptContentTypes, "acceptContentTypes");
        Intrinsics.checkNotNullParameter(receiveContentTypeMatchers, "receiveContentTypeMatchers");
        Intrinsics.checkNotNullParameter(ignoredTypes, "ignoredTypes");
        this.serializer = serializer;
        this.acceptContentTypes = acceptContentTypes;
        this.receiveContentTypeMatchers = receiveContentTypeMatchers;
        this.ignoredTypes = ignoredTypes;
    }

    public final JsonSerializer getSerializer() {
        return this.serializer;
    }

    public JsonPlugin(JsonSerializer jsonSerializer, List list, List list2, Set set, int i, DefaultConstructorMarker defaultConstructorMarker) {
        this(jsonSerializer, (i & 2) != 0 ? CollectionsKt.listOf(ContentType.Application.INSTANCE.getJson()) : list, (i & 4) != 0 ? CollectionsKt.listOf(new JsonContentTypeMatcher()) : list2, (i & 8) != 0 ? SetsKt.plus((Set) JsonPluginKt.getDefaultCommonIgnoredTypes(), (Iterable) JsonPluginJvmKt.getDefaultIgnoredTypes()) : set);
    }

    public final List<ContentType> getAcceptContentTypes() {
        return this.acceptContentTypes;
    }

    public JsonPlugin(io.ktor.client.plugins.json.JsonPlugin.Config r9) {
        throw new UnsupportedOperationException("Method not decompiled: io.ktor.client.plugins.json.JsonPlugin.<init>(io.ktor.client.plugins.json.JsonPlugin$Config):void");
    }

    @Metadata(d1 = {"\u0000N\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0010\u0011\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0006\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0010#\n\u0002\b\u0004\n\u0002\u0018\u0002\n\u0002\b\u0006\n\u0002\u0010!\n\u0002\b\u0003\n\u0002\u0010 \n\u0002\b\n\b\u0007\u0018\u00002\u00020\u0001B\u0007¢\u0006\u0004\b\u0002\u0010\u0003J!\u0010\b\u001a\u00020\u00072\u0012\u0010\u0006\u001a\n\u0012\u0006\b\u0001\u0012\u00020\u00050\u0004\"\u00020\u0005¢\u0006\u0004\b\b\u0010\tJ\u0015\u0010\f\u001a\u00020\u00072\u0006\u0010\u000b\u001a\u00020\n¢\u0006\u0004\b\f\u0010\rJ\u0018\u0010\u000f\u001a\u00020\u0007\"\u0006\b\u0000\u0010\u000e\u0018\u0001H\u0086\b¢\u0006\u0004\b\u000f\u0010\u0003J\u0018\u0010\u0010\u001a\u00020\u0007\"\u0006\b\u0000\u0010\u000e\u0018\u0001H\u0086\b¢\u0006\u0004\b\u0010\u0010\u0003J\u0019\u0010\u0010\u001a\u00020\u00072\n\u0010\u0012\u001a\u0006\u0012\u0002\b\u00030\u0011¢\u0006\u0004\b\u0010\u0010\u0013J\u0019\u0010\u000f\u001a\u00020\u00072\n\u0010\u0012\u001a\u0006\u0012\u0002\b\u00030\u0011¢\u0006\u0004\b\u000f\u0010\u0013J\r\u0010\u0014\u001a\u00020\u0007¢\u0006\u0004\b\u0014\u0010\u0003R$\u0010\u0016\u001a\f\u0012\b\u0012\u0006\u0012\u0002\b\u00030\u00110\u00158\u0000X\u0080\u0004¢\u0006\f\n\u0004\b\u0016\u0010\u0017\u001a\u0004\b\u0018\u0010\u0019R$\u0010\u001b\u001a\u0004\u0018\u00010\u001a8\u0006@\u0006X\u0086\u000e¢\u0006\u0012\n\u0004\b\u001b\u0010\u001c\u001a\u0004\b\u001d\u0010\u001e\"\u0004\b\u001f\u0010 R\u001a\u0010\"\u001a\b\u0012\u0004\u0012\u00020\u00050!8\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\"\u0010#R\u001a\u0010$\u001a\b\u0012\u0004\u0012\u00020\n0!8\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b$\u0010#R0\u0010+\u001a\b\u0012\u0004\u0012\u00020\u00050%2\f\u0010&\u001a\b\u0012\u0004\u0012\u00020\u00050%8F@FX\u0086\u000e¢\u0006\f\u001a\u0004\b'\u0010(\"\u0004\b)\u0010*R0\u0010.\u001a\b\u0012\u0004\u0012\u00020\n0%2\f\u0010&\u001a\b\u0012\u0004\u0012\u00020\n0%8F@FX\u0086\u000e¢\u0006\f\u001a\u0004\b,\u0010(\"\u0004\b-\u0010*¨\u0006/"}, d2 = {"Lio/ktor/client/plugins/json/JsonPlugin$Config;", "", "<init>", "()V", "", "Lio/ktor/http/ContentType;", "contentTypes", "", "accept", "([Lio/ktor/http/ContentType;)V", "Lio/ktor/http/ContentTypeMatcher;", "matcher", "receive", "(Lio/ktor/http/ContentTypeMatcher;)V", "T", "ignoreType", "removeIgnoredType", "Lkotlin/reflect/KClass;", LinkHeader.Parameters.Type, "(Lkotlin/reflect/KClass;)V", "clearIgnoredTypes", "", "ignoredTypes", "Ljava/util/Set;", "getIgnoredTypes$ktor_client_json", "()Ljava/util/Set;", "Lio/ktor/client/plugins/json/JsonSerializer;", "serializer", "Lio/ktor/client/plugins/json/JsonSerializer;", "getSerializer", "()Lio/ktor/client/plugins/json/JsonSerializer;", "setSerializer", "(Lio/ktor/client/plugins/json/JsonSerializer;)V", "", "_acceptContentTypes", "Ljava/util/List;", "_receiveContentTypeMatchers", "", "value", "getAcceptContentTypes", "()Ljava/util/List;", "setAcceptContentTypes", "(Ljava/util/List;)V", "acceptContentTypes", "getReceiveContentTypeMatchers", "setReceiveContentTypeMatchers", "receiveContentTypeMatchers", "ktor-client-json"}, k = 1, mv = {2, 1, 0}, xi = 48)
    @KtorDsl
    public static final class Config {
        private JsonSerializer serializer;
        private final Set<KClass<?>> ignoredTypes = CollectionsKt.toMutableSet(SetsKt.plus((Set) JsonPluginJvmKt.getDefaultIgnoredTypes(), (Iterable) JsonPluginKt.getDefaultCommonIgnoredTypes()));
        private final List<ContentType> _acceptContentTypes = CollectionsKt.mutableListOf(ContentType.Application.INSTANCE.getJson());
        private final List<ContentTypeMatcher> _receiveContentTypeMatchers = CollectionsKt.mutableListOf(new JsonContentTypeMatcher());

        public final Set<KClass<?>> getIgnoredTypes$ktor_client_json() {
            return this.ignoredTypes;
        }

        public final JsonSerializer getSerializer() {
            return this.serializer;
        }

        public final void setSerializer(JsonSerializer jsonSerializer) {
            this.serializer = jsonSerializer;
        }

        public final void setAcceptContentTypes(List<ContentType> value) {
            Intrinsics.checkNotNullParameter(value, "value");
            List<ContentType> list = value;
            if (list.isEmpty()) {
                throw new IllegalArgumentException("At least one content type should be provided to acceptContentTypes".toString());
            }
            this._acceptContentTypes.clear();
            this._acceptContentTypes.addAll(list);
        }

        public final List<ContentType> getAcceptContentTypes() {
            return this._acceptContentTypes;
        }

        public final void setReceiveContentTypeMatchers(List<? extends ContentTypeMatcher> value) {
            Intrinsics.checkNotNullParameter(value, "value");
            List<? extends ContentTypeMatcher> list = value;
            if (list.isEmpty()) {
                throw new IllegalArgumentException("At least one content type should be provided to acceptContentTypes".toString());
            }
            this._receiveContentTypeMatchers.clear();
            this._receiveContentTypeMatchers.addAll(list);
        }

        public final List<ContentTypeMatcher> getReceiveContentTypeMatchers() {
            return this._receiveContentTypeMatchers;
        }

        public final void accept(ContentType... contentTypes) {
            Intrinsics.checkNotNullParameter(contentTypes, "contentTypes");
            CollectionsKt.addAll(this._acceptContentTypes, contentTypes);
        }

        public final void receive(ContentTypeMatcher matcher) {
            Intrinsics.checkNotNullParameter(matcher, "matcher");
            this._receiveContentTypeMatchers.add(matcher);
        }

        public final <T> void ignoreType() {
            Intrinsics.reifiedOperationMarker(4, "T");
            ignoreType(Reflection.getOrCreateKotlinClass(Object.class));
        }

        public final <T> void removeIgnoredType() {
            Intrinsics.reifiedOperationMarker(4, "T");
            removeIgnoredType(Reflection.getOrCreateKotlinClass(Object.class));
        }

        public final void removeIgnoredType(KClass<?> type) {
            Intrinsics.checkNotNullParameter(type, "type");
            this.ignoredTypes.remove(type);
        }

        public final void ignoreType(KClass<?> type) {
            Intrinsics.checkNotNullParameter(type, "type");
            this.ignoredTypes.add(type);
        }

        public final void clearIgnoredTypes() {
            this.ignoredTypes.clear();
        }
    }

    public final boolean canHandle$ktor_client_json(ContentType contentType) {
        boolean z;
        Intrinsics.checkNotNullParameter(contentType, "contentType");
        List<ContentType> list = this.acceptContentTypes;
        if (!(list instanceof Collection) || !list.isEmpty()) {
            Iterator<T> it2 = list.iterator();
            while (it2.hasNext()) {
                if (contentType.match((ContentType) it2.next())) {
                    z = true;
                    break;
                }
            }
        }
        z = false;
        List<ContentTypeMatcher> list2 = this.receiveContentTypeMatchers;
        if (!z) {
            List<ContentTypeMatcher> list3 = list2;
            if (!(list3 instanceof Collection) || !list3.isEmpty()) {
                Iterator<T> it3 = list3.iterator();
                while (it3.hasNext()) {
                    if (((ContentTypeMatcher) it3.next()).contains(contentType)) {
                    }
                }
            }
            return false;
        }
        return true;
    }

    @Metadata(d1 = {"\u00004\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\u0010\u0002\n\u0002\u0018\u0002\n\u0002\b\u0004\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u0005\b\u0086\u0003\u0018\u00002\u000e\u0012\u0004\u0012\u00020\u0002\u0012\u0004\u0012\u00020\u00030\u0001B\t\b\u0002¢\u0006\u0004\b\u0004\u0010\u0005J(\u0010\n\u001a\u00020\u00032\u0017\u0010\t\u001a\u0013\u0012\u0004\u0012\u00020\u0002\u0012\u0004\u0012\u00020\u00070\u0006¢\u0006\u0002\b\bH\u0016¢\u0006\u0004\b\n\u0010\u000bJ\u001f\u0010\u000f\u001a\u00020\u00072\u0006\u0010\f\u001a\u00020\u00032\u0006\u0010\u000e\u001a\u00020\rH\u0016¢\u0006\u0004\b\u000f\u0010\u0010R \u0010\u0012\u001a\b\u0012\u0004\u0012\u00020\u00030\u00118\u0016X\u0096\u0004¢\u0006\f\n\u0004\b\u0012\u0010\u0013\u001a\u0004\b\u0014\u0010\u0015¨\u0006\u0016"}, d2 = {"Lio/ktor/client/plugins/json/JsonPlugin$Plugin;", "Lio/ktor/client/plugins/HttpClientPlugin;", "Lio/ktor/client/plugins/json/JsonPlugin$Config;", "Lio/ktor/client/plugins/json/JsonPlugin;", "<init>", "()V", "Lkotlin/Function1;", "", "Lkotlin/ExtensionFunctionType;", "block", "prepare", "(Lkotlin/jvm/functions/Function1;)Lio/ktor/client/plugins/json/JsonPlugin;", "plugin", "Lio/ktor/client/HttpClient;", "scope", "install", "(Lio/ktor/client/plugins/json/JsonPlugin;Lio/ktor/client/HttpClient;)V", "Lio/ktor/util/AttributeKey;", "key", "Lio/ktor/util/AttributeKey;", "getKey", "()Lio/ktor/util/AttributeKey;", "ktor-client-json"}, k = 1, mv = {2, 1, 0}, xi = 48)
    public static final class Companion implements HttpClientPlugin<Config, JsonPlugin> {
        public Companion(DefaultConstructorMarker defaultConstructorMarker) {
            this();
        }

        private Companion() {
        }

        @Override
        public AttributeKey<JsonPlugin> getKey() {
            return JsonPlugin.key;
        }

        @Override
        public JsonPlugin prepare(Function1<? super Config, Unit> block) {
            Intrinsics.checkNotNullParameter(block, "block");
            Config config = new Config();
            block.invoke(config);
            JsonSerializer serializer = config.getSerializer();
            if (serializer == null) {
                serializer = DefaultJvmKt.defaultSerializer();
            }
            return new JsonPlugin(serializer, CollectionsKt.toList(config.getAcceptContentTypes()), config.getReceiveContentTypeMatchers(), config.getIgnoredTypes$ktor_client_json());
        }

        @Override
        public void install(JsonPlugin plugin, HttpClient scope) {
            Intrinsics.checkNotNullParameter(plugin, "plugin");
            Intrinsics.checkNotNullParameter(scope, "scope");
            scope.getRequestPipeline().intercept(HttpRequestPipeline.INSTANCE.getTransform(), new JsonPlugin$Plugin$install$1(plugin, null));
            scope.getResponsePipeline().intercept(HttpResponsePipeline.INSTANCE.getTransform(), new JsonPlugin$Plugin$install$2(plugin, null));
        }
    }

    static {
        KType kType = null;
        KClass orCreateKotlinClass = Reflection.getOrCreateKotlinClass(JsonPlugin.class);
        try {
            kType = Reflection.typeOf(JsonPlugin.class);
        } catch (Throwable unused) {
        }
        key = new AttributeKey<>("Json", new TypeInfo(orCreateKotlinClass, kType));
    }
}