Open devrimaksakal opened 5 years ago
Do you have a stack trace? Also, please use GitHub Markdown formatting for your issues (I updated your issue for you above), it makes it far more readable.
Apologies, naive in Github markdown. Tried to format this one.. I have call trace. No stack trace...
2019-01-30 13:12:38.936 [nettyCallPool-4-1] TRACE Application - Trace for [RefData, finder, v1, findByIdList, x]
/, segment:0 -> SUCCESS @ /TestData/finder/v1/findByIdList/x/(method:POST))
/apidocs, segment:0 -> FAILURE "Selector didn't match" @ /apidocs)
/(method:GET), segment:0 -> FAILURE "Selector didn't match" @ /(method:GET))
/TestData, segment:1 -> SUCCESS @ /TestData/finder/v1/findByIdList/x/(method:POST))
/TestData/finder, segment:2 -> SUCCESS @ /TestData/finder/v1/findByIdList/x/(method:POST))
/TestData/finder/v1, segment:3 -> SUCCESS @ /TestData/finder/v1/findByIdList/x/(method:POST))
/TestData/finder/v1/getRoutes, segment:3 -> FAILURE "Selector didn't match" @ /TestData/finder/v1/getRoutes)
/TestData/finder/v1/findById, segment:3 -> FAILURE "Selector didn't match" @ /TestData/finder/v1/findById)
/TestData/finder/v1/findByIdList, segment:4 -> SUCCESS @ /TestData/finder/v1/findByIdList/x/(method:POST))
/TestData/finder/v1/findByIdList/(method:POST), segment:4 -> FAILURE "Not all segments matched" @ /TestData/finder/v1/findByIdList/(method:POST))
/TestData/finder/v1/findByIdList/x, segment:5 -> SUCCESS @ /TestData/finder/v1/findByIdList/x/(method:POST))
/TestData/finder/v1/findByIdList/x/(method:POST), segment:5 -> SUCCESS @ /TestData/finder/v1/findByIdList/x/(method:POST))
/{...}, segment:0 -> FAILURE "Better match was already found" @ /{...})
2019-01-30 13:12:38.992 [nettyCallPool-4-1] TRACE Application - 415 Unsupported Media Type: POST - /TestData/finder/v1/findByIdList/x
You need to install one of the converters to convert your JSON to the TestModel
.
The simplest way to do that is to either use the ktor plugin for Gson or Jackson.
I have this in the module:
install(ContentNegotiation) {
gson {
setPrettyPrinting()
setDateFormat(LocalDate.now().toString())
}
register(ContentType.Any, GsonConverter())
}
but post is located in another file
Update: In the same handler file when i put another post method (io.ktor.locations.post
) and send the same json
in the body
, it parse and process the post request
just fine. Issue is not json
parsing/serializing. Something around the library, either the way i implemented (which i followed the example) or the library has issues.
I think your next step is to explore this in a debugger and see where you are getting the 415 from.
Sorry I can't be of more assistance, but I don't really have enough information at the moment to be of more help.
Thank you I found the problem. The issue with complex data structures parsing/mapping/serializing: when I try to put a Map<String, List<String>>
equivalent json
in the body, it cannot serialize into custom data object as per example (tried wrapper objects to, no luck). It cannot even serialize into Map<Any, Any>
. So, I had to accept as Any
and then build the json
out of that. The confusing part was that whatever the exception is in the post
, it always return Http 415 error
.
Thank you...
I am able to test get methods (via curl and swagger client) with no issues. but post method never parse the json body. Always returns HTTP 415 Unsupported Media error.
body:
Thanks in advance..