In Micronaut Controller parsing the post request using JSON object. I expect it to not include quotes, but it quotes in the database insert.
Posting like this:
curl -X POST --header "Content-Type: application/json" -d '{"bookid":3,"name":"C++"}' http://localhost:8880/book/save
Saving like this:
String bookid=JSON?.bookid
String name=JSON?.name
def b =bookService.save(bookid,name
in database It stores like this:
+--------+-------+
| bookid | name |
+--------+-------+
| 3 | "C++" |
+--------+-------+
I expect book name just C++
Thanks SR
You haven't provided enough information about your project to know what is going on but the project at https://github.com/jeffbrown/sfgroupsjsonbinding/tree/master demonstrates how the built in binding stuff works. See the README.md file there.
package sfgroupsjsonbinding
import io.micronaut.http.annotation.Controller
import io.micronaut.http.annotation.Get
import io.micronaut.http.annotation.Post
@Controller('/book')
class BookController {
private PersonService personService
BookController(PersonService personService) {
this.personService = personService
}
@Get('/')
List<Person> list() {
personService.list()
}
@Post('/')
Person save(Person person) {
personService.save person
}
@Get('/{id}')
Person get(long id) {
personService.get id
}
}
Interacting With The App
$ curl -H "Content-Type: application/json" -d '{"name":"Jeff"}' http://localhost:8080/book
{"name":"Jeff","id":1}
$
$ curl -H "Content-Type: application/json" -d '{"name":"Jake"}' http://localhost:8080/book
{"name":"Jake","id":2}
$
$ curl -H "Content-Type: application/json" -d '{"name":"Zack"}' http://localhost:8080/book
{"name":"Zack","id":3}
$
$ curl http://localhost:8080/book
[{"name":"Jeff","id":1},{"name":"Jake","id":2},{"name":"Zack","id":3}]
$
$ curl http://localhost:8080/book/1
{"name":"Jeff","id":1}
$
$ curl http://localhost:8080/book/2
{"name":"Jake","id":2}
$
$ curl http://localhost:8080/book/3
{"name":"Zack","id":3}
$