Sample project for Ktor demonstrating content negotiation feature using Jackson.
Run this project with:
./gradlew :jackson:run
Use the following command scripts for testing:
curl -v --compress --header "Accept: application/json" http://localhost:8080/v1
Should respond with something like:
{
"name" : "root",
"items" : [ {
"key" : "A",
"value" : "Apache"
}, {
"key" : "B",
"value" : "Bing"
} ],
"date" : [ 2018, 3, 2 ]
}
The result is pretty printed, to show off how to configure gson, but it is possible to use the default gson as well
Another test:
curl -v --compress --header "Accept: application/json" http://localhost:8080/v1/item/A
Response:
{
"key": "A",
"value": "Apache"
}
You can make requests to this sample server using Ktor HTTP client. See json-client sample.