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
4444
4545class JsonDeserializationHandler (private val objectMapper : ObjectMapper ) : DeserializationHandler {
4646
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 " )
4949
5050 override fun supports (input : APIGatewayProxyRequestEvent ) =
5151 if (input.contentType() == null )
5252 false
5353 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) }
5556 }
5657
5758 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 =
2020 if (this .`is `(other))
2121 true
2222 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())
2726 }
Original file line number Diff line number Diff line change @@ -57,4 +57,36 @@ class JsonDeserializationHandlerTest {
5757 )
5858 )
5959 }
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+ }
6092}
You can’t perform that action at this time.
0 commit comments