Skip to content

Commit d7d244c

Browse files
committed
Add ContentNegotiation KClass methods for ignoring types
1 parent 504fa2d commit d7d244c

File tree

6 files changed

+60
-12
lines changed

6 files changed

+60
-12
lines changed

ktor-client/ktor-client-plugins/ktor-client-content-negotiation/api/ktor-client-content-negotiation.api

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ public final class io/ktor/client/plugins/contentnegotiation/ContentNegotiation
99
public final class io/ktor/client/plugins/contentnegotiation/ContentNegotiation$Config : io/ktor/serialization/Configuration {
1010
public fun <init> ()V
1111
public final fun clearIgnoredTypes ()V
12-
public final fun getIgnoredTypes ()Ljava/util/Set;
12+
public final fun ignoreType (Lkotlin/reflect/KClass;)V
1313
public final fun register (Lio/ktor/http/ContentType;Lio/ktor/serialization/ContentConverter;Lio/ktor/http/ContentTypeMatcher;Lkotlin/jvm/functions/Function1;)V
1414
public fun register (Lio/ktor/http/ContentType;Lio/ktor/serialization/ContentConverter;Lkotlin/jvm/functions/Function1;)V
15+
public final fun removeIgnoredType (Lkotlin/reflect/KClass;)V
1516
}
1617

1718
public final class io/ktor/client/plugins/contentnegotiation/ContentNegotiation$Plugin : io/ktor/client/plugins/HttpClientPlugin {

ktor-client/ktor-client-plugins/ktor-client-content-negotiation/common/src/io/ktor/client/plugins/contentnegotiation/ContentNegotiation.kt

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ public class ContentNegotiation internal constructor(
5353
val contentTypeMatcher: ContentTypeMatcher
5454
)
5555

56-
@PublishedApi
5756
internal val ignoredTypes: MutableSet<KClass<*>> =
5857
(DefaultIgnoredTypes + DefaultCommonIgnoredTypes).toMutableSet()
5958

@@ -98,14 +97,30 @@ public class ContentNegotiation internal constructor(
9897
* The list contains the [HttpStatusCode], [ByteArray], [String] and streaming types by default.
9998
*/
10099
public inline fun <reified T> ignoreType() {
101-
ignoredTypes.add(T::class)
100+
ignoreType(T::class)
102101
}
103102

104103
/**
105104
* Remove [T] from the list of types that should be ignored by [ContentNegotiation].
106105
*/
107106
public inline fun <reified T> removeIgnoredType() {
108-
ignoredTypes.remove(T::class)
107+
removeIgnoredType(T::class)
108+
}
109+
110+
/**
111+
* Remove [type] from the list of types that should be ignored by [ContentNegotiation].
112+
*/
113+
public fun removeIgnoredType(type: KClass<*>) {
114+
ignoredTypes.remove(type)
115+
}
116+
117+
/**
118+
* Adds a [type] to the list of types that should be ignored by [ContentNegotiation].
119+
*
120+
* The list contains the [HttpStatusCode], [ByteArray], [String] and streaming types by default.
121+
*/
122+
public fun ignoreType(type: KClass<*>) {
123+
ignoredTypes.add(type)
109124
}
110125

111126
/**

ktor-client/ktor-client-plugins/ktor-client-json/api/ktor-client-json.api

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ public final class io/ktor/client/plugins/json/JsonPlugin$Config {
1313
public final fun accept ([Lio/ktor/http/ContentType;)V
1414
public final fun clearIgnoredTypes ()V
1515
public final fun getAcceptContentTypes ()Ljava/util/List;
16-
public final fun getIgnoredTypes ()Ljava/util/Set;
1716
public final fun getReceiveContentTypeMatchers ()Ljava/util/List;
1817
public final fun getSerializer ()Lio/ktor/client/plugins/json/JsonSerializer;
18+
public final fun ignoreType (Lkotlin/reflect/KClass;)V
1919
public final fun receive (Lio/ktor/http/ContentTypeMatcher;)V
20+
public final fun removeIgnoredType (Lkotlin/reflect/KClass;)V
2021
public final fun setAcceptContentTypes (Ljava/util/List;)V
2122
public final fun setReceiveContentTypeMatchers (Ljava/util/List;)V
2223
public final fun setSerializer (Lio/ktor/client/plugins/json/JsonSerializer;)V

ktor-client/ktor-client-plugins/ktor-client-json/common/src/io/ktor/client/plugins/json/JsonPlugin.kt

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ public class JsonPlugin internal constructor(
7070
@KtorDsl
7171
public class Config {
7272

73-
@PublishedApi
7473
internal val ignoredTypes: MutableSet<KClass<*>> =
7574
(DefaultIgnoredTypes + DefaultCommonIgnoredTypes).toMutableSet()
7675

@@ -136,14 +135,30 @@ public class JsonPlugin internal constructor(
136135
* The list contains the [HttpStatusCode], [ByteArray], [String] and streaming types by default.
137136
*/
138137
public inline fun <reified T> ignoreType() {
139-
ignoredTypes.add(T::class)
138+
ignoreType(T::class)
140139
}
141140

142141
/**
143142
* Remove [T] from the list of types that should be ignored by [ContentNegotiation].
144143
*/
145144
public inline fun <reified T> removeIgnoredType() {
146-
ignoredTypes.remove(T::class)
145+
removeIgnoredType(T::class)
146+
}
147+
148+
/**
149+
* Remove [type] from the list of types that should be ignored by [ContentNegotiation].
150+
*/
151+
public fun removeIgnoredType(type: KClass<*>) {
152+
ignoredTypes.remove(type)
153+
}
154+
155+
/**
156+
* Adds a [type] to the list of types that should be ignored by [ContentNegotiation].
157+
*
158+
* The list contains the [HttpStatusCode], [ByteArray], [String] and streaming types by default.
159+
*/
160+
public fun ignoreType(type: KClass<*>) {
161+
ignoredTypes.add(type)
147162
}
148163

149164
/**

ktor-server/ktor-server-plugins/ktor-server-content-negotiation/api/ktor-server-content-negotiation.api

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ public final class io/ktor/server/plugins/contentnegotiation/ContentNegotiationC
33
public final fun accept (Lkotlin/jvm/functions/Function2;)V
44
public final fun clearIgnoredTypes ()V
55
public final fun getCheckAcceptHeaderCompliance ()Z
6-
public final fun getIgnoredTypes ()Ljava/util/Set;
6+
public final fun ignoreType (Lkotlin/reflect/KClass;)V
77
public fun register (Lio/ktor/http/ContentType;Lio/ktor/serialization/ContentConverter;Lkotlin/jvm/functions/Function1;)V
8+
public final fun removeIgnoredType (Lkotlin/reflect/KClass;)V
89
public final fun setCheckAcceptHeaderCompliance (Z)V
910
}
1011

ktor-server/ktor-server-plugins/ktor-server-content-negotiation/jvmAndNix/src/io/ktor/server/plugins/contentnegotiation/ContentNegotiationConfig.kt

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public class ContentNegotiationConfig : Configuration {
2929
internal val registrations = mutableListOf<ConverterRegistration>()
3030
internal val acceptContributors = mutableListOf<AcceptHeaderContributor>()
3131

32-
@PublishedApi
3332
internal val ignoredTypes: MutableSet<KClass<*>> = (DefaultCommonIgnoredTypes + DefaultIgnoredTypes).toMutableSet()
3433

3534
/**
@@ -71,14 +70,30 @@ public class ContentNegotiationConfig : Configuration {
7170
* The list contains the [HttpStatusCode] type by default.
7271
*/
7372
public inline fun <reified T> ignoreType() {
74-
ignoredTypes.add(T::class)
73+
ignoreType(T::class)
7574
}
7675

7776
/**
7877
* Remove [T] from the list of types that should be ignored by [ContentNegotiation].
7978
*/
8079
public inline fun <reified T> removeIgnoredType() {
81-
ignoredTypes.remove(T::class)
80+
removeIgnoredType(T::class)
81+
}
82+
83+
/**
84+
* Remove [type] from the list of types that should be ignored by [ContentNegotiation].
85+
*/
86+
public fun removeIgnoredType(type: KClass<*>) {
87+
ignoredTypes.remove(type)
88+
}
89+
90+
/**
91+
* Adds a [type] to the list of types that should be ignored by [ContentNegotiation].
92+
*
93+
* The list contains the [HttpStatusCode], [ByteArray], [String] and streaming types by default.
94+
*/
95+
public fun ignoreType(type: KClass<*>) {
96+
ignoredTypes.add(type)
8297
}
8398

8499
/**

0 commit comments

Comments
 (0)