File tree Expand file tree Collapse file tree 3 files changed +39
-7
lines changed
main/kotlin/io/moia/router
test/kotlin/io/moia/router Expand file tree Collapse file tree 3 files changed +39
-7
lines changed Original file line number Diff line number Diff line change @@ -44,14 +44,15 @@ class DeserializationHandlerChain(private val handlers: List<DeserializationHand
44
44
45
45
class JsonDeserializationHandler (private val objectMapper : ObjectMapper ) : DeserializationHandler {
46
46
47
- private val json = MediaType .parse(" application/json" )
48
- private val jsonStructuredSuffixWildcard = MediaType .parse(" application/*+json" )
47
+ private val json = MediaType .parse(" application/json; charset=UTF-8 " )
48
+ private val jsonStructuredSuffixWildcard = MediaType .parse(" application/*+json; charset=UTF-8 " )
49
49
50
50
override fun supports (input : APIGatewayProxyRequestEvent ) =
51
51
if (input.contentType() == null )
52
52
false
53
53
else {
54
- MediaType .parse(input.contentType()!! ).let { json.isCompatibleWith(it) || jsonStructuredSuffixWildcard.isCompatibleWith(it) }
54
+ MediaType .parse(input.contentType()!! )
55
+ .let { json.isCompatibleWith(it) || jsonStructuredSuffixWildcard.isCompatibleWith(it) }
55
56
}
56
57
57
58
override fun deserialize (input : APIGatewayProxyRequestEvent , target : KType ? ): Any? {
Original file line number Diff line number Diff line change @@ -20,8 +20,7 @@ fun MediaType.isCompatibleWith(other: MediaType): Boolean =
20
20
if (this .`is `(other))
21
21
true
22
22
else {
23
- type() == other.type() &&
24
- (subtype().contains(" +" ) && other.subtype().contains(" +" )) &&
25
- this .subtype().substringBeforeLast(" +" ) == " *" &&
26
- this .subtype().substringAfterLast(" +" ) == other.subtype().substringAfterLast(" +" )
23
+ type() == other.type() && (subtype().contains(" +" ) && other.subtype().contains(" +" )) && this .subtype()
24
+ .substringBeforeLast(" +" ) == " *" && this .subtype().substringAfterLast(" +" ) == other.subtype()
25
+ .substringAfterLast(" +" ) && (other.parameters().isEmpty || this .parameters() == other.parameters())
27
26
}
Original file line number Diff line number Diff line change @@ -57,4 +57,36 @@ class JsonDeserializationHandlerTest {
57
57
)
58
58
)
59
59
}
60
+
61
+ @Test
62
+ fun `should support json with UTF-8 charset parameter` () {
63
+ assertTrue(
64
+ deserializationHandler.supports(
65
+ APIGatewayProxyRequestEvent ()
66
+ .withHeader(" content-type" , " application/json; charset=UTF-8" )
67
+ )
68
+ )
69
+ assertTrue(
70
+ deserializationHandler.supports(
71
+ APIGatewayProxyRequestEvent ()
72
+ .withHeader(" content-type" , " application/vnd.moia.v1+json; charset=UTF-8" )
73
+ )
74
+ )
75
+ }
76
+
77
+ @Test
78
+ fun `should not support json with other charset parameter` () {
79
+ assertFalse(
80
+ deserializationHandler.supports(
81
+ APIGatewayProxyRequestEvent ()
82
+ .withHeader(" content-type" , " application/json; charset=UTF-16" )
83
+ )
84
+ )
85
+ assertFalse(
86
+ deserializationHandler.supports(
87
+ APIGatewayProxyRequestEvent ()
88
+ .withHeader(" content-type" , " application/vnd.moia.v1+json; charset=UTF-16" )
89
+ )
90
+ )
91
+ }
60
92
}
You can’t perform that action at this time.
0 commit comments