Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- data class PurchaseOrder(val buyer: String, val seller: String,
- val poNumber: String, val date: String,
- val vendorReference: String)
- install(ContentNegotiation) {
- gson {
- setDateFormat(DateFormat.LONG)
- setPrettyPrinting()
- }
- post("/purchaseOrder"){
- val po = call.receive<PurchaseOrder>()
- println("purchase order: ${po.toString()}")
- call.respondText("post received", contentType =
- ContentType.Text.Plain)
- {
- "PurchaseOrder" : {
- "buyer": "buyer a",
- "seller": "seller A",
- "poNumber": "PO1234",
- "date": "27-Jun-2018",
- "vendorReference": "Ref1234"
- }
- }
- purchase order: PurchaseOrder(buyer=null, seller=null, poNumber=null,
- date=null, vendorReference=null)
- val channel = call.request.receiveChannel()
- val ba = ByteArray(channel.availableForRead)
- channel.readFully(ba)
- val s = ba.toString(Charset.defaultCharset())
- println(s) // prints JSON
- val gson = Gson()
- val po = gson.fromJson(s, PurchaseOrder::class.java)
- println("buyer = ${po.buyer}" //prints null
Add Comment
Please, Sign In to add comment